这应该很简单,但我真的很难做到正确.我只需要一个简单的ttk ComboBox,它可以根据选择的变化更新变量.
在下面的示例中,我需要value_of_combo每次进行新选择时自动更新变量的值.
from Tkinter import *
import ttk
class App:
value_of_combo = 'X'
def __init__(self, parent):
self.parent = parent
self.combo()
def combo(self):
self.box_value = StringVar()
self.box = ttk.Combobox(self.parent, textvariable=self.box_value)
self.box['values'] = ('X', 'Y', 'Z')
self.box.current(0)
self.box.grid(column=0, row=0)
if __name__ == '__main__':
root = Tk()
app = App(root)
root.mainloop()
Run Code Online (Sandbox Code Playgroud) 我写了一个小法拉转换器来学习GUI编程.它很棒,看起来很精致.唯一的问题是我似乎无法弄清楚如何控制我的ttk.Combobox选择中出现的这种奇怪的突出显示.我确实使用过ttk.Style(),但它只改变了ttk.Combobox背景,条目等的颜色.我也试过改变openbox/gtk主题.

我在谈论文字"microfarads(uF)"中的内容.
如果突出显示整个盒子,那就没关系了.但我宁愿让它完全消失.
我怎样才能操纵ttk.Combobox选择的亮点?
# what the farad?
# thomas kirkpatrick (jtkiv)
from tkinter import *
from tkinter import ttk
# ze la programma.
def conversion(*args):
# this is the numerical value
inV = float(inValue.get())
# these two are the unit (farads, microfarads, etc.) values
inU = inUnitsValue.current()
outU = outUnitsValue.current()
# "mltplr" is multiplied times inValue (inV)
if inU == outU:
mltplr = 1
else:
mltplr = 10**((outU - …Run Code Online (Sandbox Code Playgroud)