我想知道如何在PyQt4中执行以下操作:
import tkinter as tk
LARGE_FONT= ("Verdana", 12)
class SeaofBTCapp(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, 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", font=LARGE_FONT)
label.pack(pady=10,padx=10)
btn = tk.Button(self, text="Page One", command= lambda: controller.show_frame(PageOne))
btn.pack()
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="Page One", font=LARGE_FONT)
label.pack(pady=10,padx=10)
btn = tk.Button(self, text="Home", command= lambda: controller.show_frame(StartPage))
btn.pack()
app = SeaofBTCapp()
app.mainloop()
我将有多个页面,并希望能够轻松定义。我仍然是python编码的新手,我还在学习PyQt4是如何工作的,但是我的项目将至少有4个页面需要切换,我不希望代码太长,每个都定义相同的东西页面的课程。所有帮助将不胜感激。先感谢您。
答案 0 :(得分:1)