我和我的朋友正在製作一個顯示4個單選按鈕和文本的窗口,我們正努力在底部添加兩個按鈕。將單選按鈕添加到Tkinter
這裏是我們的代碼:
from Tkinter import *
import time
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
v = IntVar()
Radiobutton(master, text="0 for not at all", variable=v, value=1).pack(side=TOP)
Radiobutton(master, text="1 for somewhat", variable=v, value=2).pack(side=TOP)
Radiobutton(master, text="2 for moderatly", variable=v, value=3).pack(side=TOP)
Radiobutton(master, text="3 for a lot", variable=v, value=4).pack(side=TOP)
self.button = Button(master, text="BACK", fg="red", command=self.button6)
self.button.pack(side=BOTTOM)
self.button = Button(master, text="NEXT", fg="red", command=self.button5)
self.button.pack(side=BOTTOM)
def button6(self):
print "Sam is awesome!GAJONGA"
def button5(self):
print "PYTHON FOR THE WIN! GIAN SAYS PYTHON = FILTHY"
w = Label(master, text="1. Anxiety, nervousness, worry or fear")
w.pack()
master = Tk()
master.mainloop()
運行這給了我們以下錯誤:
Traceback (most recent call last):
File "/Volumes/CHROME USB/STORAGE/TKinker GUI/Radiobutton example.py", line 36,
in <module>
w = Label(master, text="1. Anxiety, nervousness, worry or fear")
NameError: name 'master' is not defined
感謝您發表評論伊格納西奧,但我仍然要多一個小白的:-(明白你的意思。我們的大部分代碼是從互聯網上的例子中剪切和粘貼,我們很快學習到:-D PS STACKOVERFLOW.COM真棒! – gian848396