簡體   English   中英

選擇 combobox 值 tkinter python 時刪除突出顯示顏色

[英]remove highlight color when choosing a combobox value 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()

所以我發現在嘗試更改主題時如何插入配置元素很重要。 這三行對我有用。

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')

我知道您的問題已經得到解答,但我想最簡單的方法是在您的樣式中添加以下命令:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM