|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
各位大佬,小弟在初学tkinter时碰到个问题,button组件关联的函数有多个动作的时候,或者说用户点了button之后的页面又有button,就变成函数里面套函数了,总感觉这样的写法不太对,请问有没有更简洁明了的方法呢?下面是我的button又button,函数套函数的写法:
- from tkinter import *
- from tkinter.messagebox import *
- root = Tk()
- text = Text(root)
- text.pack()
- text.insert(INSERT, '这是主窗口,用户在此窗口上点确定后弹窗开始选择数字,选定点确定关闭弹窗,并获得值')
- def firstfunc():
- top = Toplevel(root)
- s = Scale(top, from_=0, to=42)
- s.pack()
- def secondfunc_in_firstfunc(s):
- if askyesno('提示', '这个窗口用于获取用户选定的值'):
- s = s.get()
- top.withdraw()
- text.insert(INSERT, s)
- Button(top, text='确定后,函数关闭此窗口,并获得选定的值', command=lambda: secondfunc_in_firstfunc(s)).pack()
- Button(root, text='确定', command=firstfunc).pack()
- mainloop()
复制代码 |
|