0
我有兩個組合框我想用一個函數來控制,但我正在努力理解如何從哪個組合框調用回調中獲取值。將2個組合框鏈接到一個函數並返回它的值
from Tkinter import *
import ttk
class App(Frame):
def __init__(self, parent):
self.parent = parent
self.value_of_combo = "X"
self.initUI()
def information(self, type):
combo_var = self.type.get()
print combo_var
def initUI(self):
# Label
self.configlbl = Label(self.parent, text="Description")
self.configlbl.pack(side=LEFT)
# Type
self.linear_value = StringVar()
self.linear = ttk.Combobox(self.parent, textvariable=self.linear_value)
self.linear.bind('<<ComboboxSelected>>', self.information('linear'))
self.linear.pack(side=LEFT)
self.linear['values'] = ('X', 'Y', 'Z')
# UTCN
self.utcn_value = StringVar()
self.utcn = ttk.Combobox(self.parent, textvariable=self.utcn_value)
self.utcn.bind('<<ComboboxSelected>>', self.information('utcn'))
self.utcn.pack(side=LEFT)
self.utcn['values'] = ('A', 'B', 'C')
if __name__ == '__main__':
root = Tk()
app = App(root)
root.mainloop()
這段代碼在它最簡單的形式,在這裏我提出來,它是需要一些額外的螺母和螺栓的信息功能。
現貨! – pickles 2015-02-06 08:42:43