import tkinter as tk
class program(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args,**kwargs)
self.title("Staff Management System")
self.geometry("1280x720")
self.columnconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
self.frames = {}
#frame that will hold all the elements
container = tk.Frame(self)
container.grid(row=1,column=0,)
for i in range(128):
container.columnconfigure(i,weight=1)
for i in range(128):
container.rowconfigure(i,weight=1)
#listing frames (pages) to be controlled
for F in (homePage, staffLogin):
frame = F(parent=container, controller=self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky = "nsew")
self.show_frame(staffLogin)
def show_frame(self, page):
frame = self.frames[page]
frame.tkraise()
class homePage(tk.Frame):
def __init__(self, parent, controller, *args, **kwargs):
tk.Frame.__init__(self,parent,*args, **kwargs)
self.controller = controller
promotionsButton = tk.Button(self, text="Promotions", height = 4)
promotionsButton.grid(row=1, column = 128, sticky='w')
staffLoginButton = tk.Button(self, text="Staff Login", width = 50, height = 20)
staffLoginButton.grid(row=1, column=1)
managerLoginButton = tk.Button(self, text="Manager Login", width = 50, height = 20)
managerLoginButton.grid(row=1,column=2)
class staffLogin(tk.Frame):
def __init__(self, parent, controller, *args, **kwargs):
tk.Frame.__init__(self,parent, *args, **kwargs)
self.controller = controller
userIDLabel = tk.Label(self, text = "UserID:")
userIDInput = tk.Entry(self, width=50, font=("Helvectia",16))
userIDLabel.grid(sticky="W", row=67,column=59)
userIDInput.grid(row=67, column=60)
userPasswordLabel = tk.Label(self, text = "Password:")
userPasswordInput = tk.Entry(self,width=50, font=("Helvectia",16))
userPasswordLabel.grid(sticky="W", row=70, column=59)
userPasswordInput.grid(row=70, column=60)
loginButton = tk.Button(self, text="Login", height=2, width=7)
loginButton.grid(sticky="E",row = 71, column=60)
thing = program()
thing.mainloop()
im trying to use the container column and row configure methods in order to create 128 'boxes' that i am able to grid widgets in for each of my pages. However, it doesn't work when i run the program, when i try passing 'parent' instead of 'self' when i create my widgets in my different pages, my show_frame function doesnt work and instead it displays the widgets from both of my pages at the same time.
You're calling rowconfigure
and columnconfigure
on the container, but the container only has a single row and a single column that is used to hold each "page". You need to be calling those methods on each page rather than on the container.
class homePage():
def __init__(self, parent, controller, *args, **kwargs):
...
for i in range(128):
self.columnconfigure(i,weight=1)
for i in range(128):
self.rowconfigure(i,weight=1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.