选择combobox值tkinter python时删除突出显示的颜色
当用户从组合框下拉列表中选择值时,是否可以选择删除颜色突出显示?我正在使用主题“蛤”,并尝试了其他带有不同想法的主题,但到目前为止没有运气。这是我要删除的图像:
这是我的代码下面:
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()
Is there an option to remove the color highlighting when the user chooses the value from the combo box drop down? I'm using the theme "clam" and tried other themes with different ideas but no luck so far. Here is an image of what I'm trying to remove:
Here is my code below:
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,我发现当您尝试更改主题时,您如何插入配置元素很重要。这三行对我有用。
So I found out there is an importance of how you insert the config elements when you try to change the theme. Those three lines worked for me.
我知道您的问题已经回答,但我想最简单的方法是将以下命令添加到您的样式中:
I know your question is already answered but I guess the simplest way is to add to your style the following commands: