-2
我想在此代碼中放置一個菜單(我在此網站上找到該菜單);但我不知道如何, 並沒有找到答案。Python中的菜單tk
編輯:主要的問題是,每當我試圖把出現在其他窗口(如TK#2)
EDIT2菜單:我已經解決了這個問題,謝謝。
import tkinter as tk
TITLE_FONT = ("Helvetica", 18, "bold")
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, c):
frame = self.frames[c]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="This is the start page", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
button1 = tk.Button(self, text="Go to Page One",
command=lambda: controller.show_frame(PageOne))
button1.pack()
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="This is page 1", font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
button = tk.Button(self, text="Go to the start page",
command=lambda: controller.show_frame(StartPage))
button.pack()
if __name__ == "__main__":
app = SampleApp()
app.mainloop()
你可能有更多的運氣,如果你發佈特定的代碼,並提及您遇到,而不是請求,有人編寫代碼對你的問題。 – 2013-03-04 21:37:22
問題是,每次我把一個菜單,該菜單是在其他窗口 – 2013-03-04 21:38:29
@ EmmettJ.Butler,我不能把具體的代碼,因爲我不知道什麼使這個問題 – 2013-03-04 21:40:38