|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码如下所示,我想实现Radiobutton的替换,为什么这样替换不了呢?
- from tkinter import *
- x = 0
- root = Tk()
- answers = {}
- answers[0] = [('草莓', 2), ('苹果', 3), ('西瓜', 5), ('菠萝', 10), ('橘子', 15)]
- answers[1] = [('郊外', 2), ('电影院', 3), ('公园', 5), ('商场', 10), ('酒吧', 15), ('练歌房', 20)]
- v = StringVar()
- if x <= 14:
- if x == 0:
- for ans, point in answers[x]:
- choices1 = Radiobutton(root, text=ans, variable=v, value=point, padx=100, justify='left')
- choices1.pack()
- if x == 1:
- for ans, point in answers[1]:
- choices1 = Radiobutton(root, text=ans, variable=v, value=point, padx=100, justify='left')
- choices1.pack()
- def point_plus_change():
- global x
- x += 1
- butt_addpoint = Button(root, text='确定', font=('黑体', 10), command=point_plus_change)
- butt_addpoint.pack()
- root.mainloop()
复制代码
点击确认按钮之后没有反应,如图所示
- from tkinter import *
- x = 0
- root = Tk()
- answers = {0: [('草莓', 2), ('苹果', 3), ('西瓜', 5), ('菠萝', 10), ('橘子', 15)],
- 1: [('郊外', 2), ('电影院', 3), ('公园', 5), ('商场', 10), ('酒吧', 15), ('练歌房', 20)]}
- v = StringVar()
- choices = [] # 保存 Radiobutton 的一个列表
- for ans, point in answers[x]:
- choices1 = Radiobutton(root, text=ans, variable=v, value=point, padx=100, justify='left')
- choices1.pack()
- choices.append(choices1)
- def point_plus_change():
- global x
- x += 1
- x %= 2 # 对 2 求余数
- if x <= 14:
- if x == 0:
- for (ans, point), choices1 in zip(answers[0], choices):
- choices1.config(text=ans, variable=v, value=point, padx=100, justify='left')
- if x == 1:
- for (ans, point), choices1 in zip(answers[1], choices):
- choices1.config(text=ans, variable=v, value=point, padx=100, justify='left')
- butt_addpoint = Button(root, text='确定', font=('黑体', 10), command=point_plus_change)
- butt_addpoint.pack()
- root.mainloop()
复制代码
|
|