2
我試圖啓動一個Tkinter應用程序,該應用程序遵循Class menu in Tkinter Gui以保持整潔,同時還爲此添加了此功能。按鈕欄,單選酒吧等喜歡的東西:菜單,按鈕等Tkinter GUI中的酒吧
from Tkinter import *
def clickTest():
print "Click!"
class App(Tk):
def __init__(self):
Tk.__init__(self)
menuBar = MenuBar(self)
buttonBar = ButtonBar(self)
self.config(menu=menuBar)
buttonBar.grid(row=0, column=0) ???
class MenuBar(Menu):
def __init__(self, parent):
Menu.__init__(self, parent)
fileMenu = Menu(self, tearoff=False)
self.add_cascade(label="File", menu=fileMenu)
fileMenu.add_command(label="Exit", command=clickTest)
class ButtonBar(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
firstButton = Button(parent, text="1st Button", command=clickTest)
secondButton = Button(parent, text="2nd Button", command=clickTest)
if __name__ == "__main__":
app = App()
app.mainloop()
但我不知道如何讓這一切在同一窗口中顯示出來。當然,代碼是不起作用的。任何建議表示讚賞。謝謝!
很酷。謝謝。是的,我也是用grid()來解決它的。感謝按鈕的父母的最後一個建議 - 爲我解決了這個問題。 – Ryan 2012-04-18 01:47:15