|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
"""
checkbutton 练习
"""
from tkinter import *
# 普通版
def normalButton():
root = Tk()
v = IntVar()
c = Checkbutton(root, text='test1', variable=v)
c.pack()
l = Label(root, textvariable=v)
l.pack()
return root.mainloop()
# 循环版
def circleButton():
root = Tk()
GIRLS = ['1', '2', '3', '4']
v = []
for girl in GIRLS:
v.append(IntVar())
b = Checkbutton(root, text=girl, variable=v[-1])
b.pack()
root.mainloop()
return
runCode = input('press 1 or 2')
if runCode==1:
normalButton()
elif runCode==2:
circleButton()
运行后发现tkinter没有弹出任何组件程序就结束了。这是为啥。
本帖最后由 1q23w31 于 2020-8-29 21:10 编辑
看这个,因为input接收到的是字符型变量,只有变为整型变量后,才能与数字比较大小
- from tkinter import *
- # 普通版
- def normalButton():
- root = Tk()
- v = IntVar()
- c = Checkbutton(root, text='test1', variable=v)
- c.pack()
- l = Label(root, textvariable=v)
- l.pack()
- return root.mainloop()
- def circleButton():
- root = Tk()
- GIRLS = ['1', '2', '3', '4']
- v = []
- for girl in GIRLS:
- v.append(IntVar())
- b = Checkbutton(root, text=girl, variable=v[-1])
- b.pack()
- root.mainloop()
- return
- runCode = int(input('press 1 or 2'))
- if runCode==1:
- normalButton()
- elif runCode==2:
- circleButton()
复制代码
|
|