【问题标题】:remove highlight color when choosing a combobox value tkinter python选择组合框值tkinter python时删除突出显示颜色
【发布时间】:2022-07-01 16:55:17
【问题描述】:

当用户从组合框下拉列表中选择值时,是否有移除颜色突出显示的选项?我正在使用主题“蛤蜊”并尝试了其他具有不同想法但没有运气的主题。这是我要删除的图像:

下面是我的代码:

clean_shift_win = Tk()
clean_shift_win.title('JUSTT Shift Request')
clean_shift_win.geometry('300x200')
dir_path_main_bg = os.path.join(dir_path, r'login window bg.png')
picture = PhotoImage(file=dir_path_main_bg, master=clean_shift_win)
clean_shift_win.option_add('*TCombobox*Listbox.selectBackground', '#30D5C8') # change 
highlight color
clean_shift_win.option_add('*TCombobox*Listbox.selectForeground', 'white') # change text 
color


clean_shift_canvas = Canvas(clean_shift_win, width=300, height=200,
                        highlightbackground='#30D5C8', highlightcolor='#30D5C8')
clean_shift_canvas.pack(fill='both', expand=True)
clean_shift_canvas.create_image(0, 0, image=picture, anchor='nw')
clean_shift_canvas.create_text(150,80,fill='turquoise',font='calibri 13 bold',
                text='Which Day You Want\n To Delete Your Shift?')

day_chose_to_delete = tk.StringVar(value='Weekday')
day_chose_to_delete_list = ttk.Combobox(clean_shift_canvas, 
textvariable=day_chose_to_delete, state='readonly', cursor='hand1', justify='center')


day_chose_to_delete_list['value'] = week
day_chose_to_delete_list.config(font=('calibri', '13'), width=15) 
day_chose_to_delete_list.place(x=70, y=110, anchor='nw')

def delete_shift():
    MsgBox = tk.messagebox.askquestion('Shift Cancellation','Are You Sure You Want To Delete This Shift', icon = 'warning')
    if MsgBox == 'yes':
        clear_cells()
        clean_shift_win.destroy()
    else:
        pass

day_to_delete_btn = ttk.Button(clean_shift_canvas, text='Delete This Shift', 
cursor='hand2', command=delete_shift)
day_to_delete_btn.place(relx=0.32, rely=0.8, relwidth=0.35, relheight=0.15)


style = ttk.Style(clean_shift_win)
style.theme_use('clam')
style.map('TButton', foreground=[('!disabled', 'white'), ('active', 'white')],
      background=[('!disabled', '#550a8a'), ('active', '#550a8a')],
      bordercolor=[('!disabled', '#550a8a'), ('active', '#550a8a')],
      borderwidth=[('!disabled', 0), ('active', 0)])

style.map('TCombobox', fieldbackground=[('!disabled', 'white'), ('!pressed', 'white')],
      background=[('!disabled', '#30D5C8'), ('active', '#30D5C8')],
      bordercolor=[('!disabled', '#30D5C8'), ('active', '#30D5C8')],
      borderwidth=[('!disabled', 0), ('active', 0)])

clean_shift_win.resizable(False, False)
dir_path_justt_icon = os.path.join(dir_path, r'JUSTT Logo.ico')
clean_shift_win.iconbitmap(dir_path_justt_icon)
clean_shift_win.mainloop()

【问题讨论】:

    标签: python tkinter combobox styles ttk


    【解决方案1】:

    所以我发现在尝试更改主题时如何插入配置元素很重要。这三行对我有用。

    style = ttk.Style()
    combostyle = ttk.Style()
    combostyle.theme_create('combostyle', parent='clam', settings = {'TCombobox': 
                                                                 {'configure': {'selectbackground': 'white',
                                                                                'fieldbackground': 'white',
                                                                                'background': '#30D5C8',
                                                                                'bordercolor':'#30D5C8',
                                                                               'selectforeground': 'black'}}})
    
    style.theme_use('combostyle')
    

    【讨论】:

      【解决方案2】:

      我知道您的问题已经得到解答,但我想最简单的方法是在您的样式中添加以下命令:

      style = ttk.Style()
      style.configure('TCombobox', selectbackground=None, selectforeground=None)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多