기본적으로 내가 알아 내려고하는 것은, 내 메뉴 막대 "버튼"을 페이지를 어떻게 변경합니까?tkinter의 내 메뉴 막대 방법을 통해 페이지를 변경하는 방법?
이미 드롭 다운 메뉴와 각 페이지의 수업을 만들었습니다. 문제는 내가 페이지를 바꿀 별도의 버튼을 만들면 작동하지만, 메뉴 바를 통해 할 때가 아닐까요?
내가 찾을 수있는 모든 튜토리얼은 버튼을 통해, 그리고 단추 만 ..
나는 tkinter
으로, 파이썬 3.6을 사용하고 있습니다.
import tkinter as tk
class MyApp(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 = {}
menu = tk.Menu(container)
betting = tk.Menu(menu, tearoff=0)
menu.add_cascade(menu=betting, label="Pages")
betting.add_command(label="PageOne",
command=lambda: controller.show_frame(PageOne))
betting.add_command(label="PageTwo",
command=lambda: controller.show_frame(PageTwo))
tk.Tk.config(self, menu=menu)
for F in (Startpage, PageOne, PageTwo):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(Startpage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class Startpage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Home")
label.pack(pady=10, padx=10)
button1 = tk.Button(self, text="page 1",
command=lambda: controller.show_frame(PageOne))
button1.pack()
button2 = tk.Button(self, text="Page Two",
command=lambda: controller.show_frame(PageTwo))
button2.pack()
# ***** PAGES *****
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Back to Home")
label.pack(pady=10, padx=10)
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(Startpage))
button1.pack()
button2 = tk.Button(self, text="Page Two",
command=lambda: controller.show_frame(PageTwo))
button2.pack()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Page Two")
label.pack(pady=10, padx=10)
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(Startpage))
button1.pack()
button2 = tk.Button(self, text="Page One",
command=lambda: controller.show_frame(PageOne))
button2.pack()
app = MyApp()
app.geometry("1200x600")
app.mainloop()
는 지금은
이
wxPython이나 tkinter 또는 다른 것에 대해 묻고 싶습니까? –
나의 나쁜, tkinter – ShrekTek
를 통해 [mcve]를 보여주십시오. 우리가 볼 수없는 코드를 고칠 수는 없습니다. –