以下Demo,我希望选择Radiobutton,对t进行赋值,但t = v.get()语句无效。
不知道应该怎么写,请指教,谢谢。
[Python] 纯文本查看 复制代码 from tkinter import *
from tkinter.ttk import *
class function:
def change_value(v, t):
print(v.get())
t = v.get()
class start_gui(Tk):
def __init__(self, parent):
self.parent = parent
def set_window(self):
w = self.parent
# 创建内容容器
content = Frame(w, padding=(30, 20, 30, 20))
v = IntVar()
v.set(0)
t = 0
fm_col_type = Frame(content)
fm_col_type.grid(column=0, row=0, sticky=(
E, W), padx=(15, 0), pady=(15, 0))
rbt_col_type_field = Radiobutton(
fm_col_type, text='字段名', variable=v, value=0, command=lambda: function.change_value(v, t))
rbt_col_type_field.grid(column=0, row=0)
rbt_col_type_col = Radiobutton(
fm_col_type, text='列名', variable=v, value=1, command=lambda: function.change_value(v, t))
rbt_col_type_col.grid(column=1, row=0, padx=(15, 0))
# 选择结果显示
lb_col_name = Label(content, text=t)
lb_col_name.grid(column=0, row=1, pady=20)
# 渲染容器
content.grid(column=0, row=0)
def action():
root = Tk()
window = start_gui(root)
window.set_window()
root.mainloop()
if __name__ == '__main__':
action()
|