有关tkinter里Radiobutton组件用法
请问这段代码有什么错误吗?import tkinter as tk
window = tk.Tk()
window.title('choice')
window.geometry('300x100')
v = tk.IntVar()
v.set(2)
tk.Radiobutton(window, text="One", variable=v, value=1).pack(anchor=W)
tk.Radiobutton(window, text="Two", variable=v, value=2).pack(anchor=W)
tk.Radiobutton(window, text="Three", variable=v, value=3).pack(anchor=W)
tk.mainloop()
这段让文本左靠齐的代码总是报错。。
tk.Radiobutton(window, text="One", variable=v, value=1).pack(anchor=W)
报错:
Traceback (most recent call last):
File "D:/python/新建文件夹/小甲鱼练习题/Radiobutton.py", line 13, in <module>
tk.Radiobutton(window, text="One", variable=v, value=1).pack(anchor=W)
NameError: name 'W' is not defined
请问如何解决? 本帖最后由 zltzlt 于 2019-8-13 10:32 编辑
import tkinter as tk
window = tk.Tk()
window.title('choice')
window.geometry('300x100')
v = tk.IntVar()
v.set(2)
tk.Radiobutton(window, text="One", variable=v, value=1).pack(anchor=tk.W)
tk.Radiobutton(window, text="Two", variable=v, value=2).pack(anchor=tk.W)
tk.Radiobutton(window, text="Three", variable=v, value=3).pack(anchor=tk.W)
tk.mainloop() W 是包含在 tkinter 包里的,所以要加上 tk. zltzlt 发表于 2019-8-13 10:30
多谢,原来这样
页:
[1]