我正在创建需要tkinter combox的应用程序。在那里,我希望组合框从应用程序的开始就具有默认值。我尝试过current()
方法,但无法正常工作。
这是我的代码片段
n= tk.StringVar()
youtubechoicesLabel = ttk.Combobox(root, font=font, justify='center', textvariable=n)
youtubechoicesLabel['values'] = ("----Download Type----",
"Mp4 720p",
"Mp4 144p",
"Video 3gp",
"Audio Mp3")
youtubechoicesLabel.current(0)
youtubechoicesLabel["background"] = '#ff0000'
youtubechoicesLabel["foreground"] = '#ffffff'
youtubechoicesLabel.pack(side=TOP, pady=20)
呼叫current()
正确无误,并且可以正常工作-由于使用了foreground
指定的白色,您只是看不到当前选择。
n = tk.StringVar()
youtubechoicesLabel = ttk.Combobox(root, font=font, justify='center', textvariable=n)
youtubechoicesLabel['values'] = ("----Download Type----",
"Mp4 720p",
"Mp4 144p",
"Video 3gp",
"Audio Mp3")
youtubechoicesLabel.current(0)
youtubechoicesLabel["background"] = '#ff0000'
#youtubechoicesLabel["foreground"] = '#ffffff' # <----- DISABLED
youtubechoicesLabel.pack(side=TOP, pady=20)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句