0
所以我一直玩python 3.2 tkinter。 今天剛剛發現單選按鈕中的文字沒有顯示在按鈕旁邊,它只顯示「0」。 另外,當我在單選按鈕語句末尾有.pack()時,它顯示錯誤'NoneType'對象沒有屬性'pack'。這很奇怪,是因爲他們在新版本中改變了。我是否需要導入其他一些東西?由於python 3.2 tkinter,單選按鈕中的文本不顯示
from tkinter import*
class Name:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self._var = IntVar()
self._fullRadio = Radiobutton(frame, text="yes", textvariable=self._var, value=1)
self._fullRadio.grid(row=2, column=0)#.pack()
self._partRadio = Radiobutton(frame, text="no", textvariable=self._var, value=2)
self._partRadio.grid(row=3)#.pack()
self._notRadio = Radiobutton(frame, text="not both", textvariable=self._var, value=3)
self._notRadio.grid(row=4)#.pack()
root = Tk()
application = Name(root)
root.mainloop()
哈哈,這就是一個愚蠢的錯誤......感謝您的幫助:) – PyJar 2013-04-11 01:23:28
您可以在同一個應用程序中混合包和網格,只是不在同一個容器(即:不在同一個框架中)。這是因爲每個人都會查看小部件大小的變化,並且(可能)會在更改大小時重新調整其管理的所有窗口的大小。那麼會發生什麼呢,那個網格根據它的規則改變了一些小部件的大小,打包注意到了這些改變,從而根據_its_規則改變了其他小部件的大小。網格注意到所有變化等。然而,在同一個_application_中同時使用grid和pack是Tkinter所有有經驗的編程人員所做的。 – 2013-04-11 10:54:39