I’m a begginer programmer and got this little project that i have to make, and i’m going totaly blind into this project, so the way im constructing my gui windows is by declaring every widget used on the class constructor, and every time i need to create a new window i just clear all widgets on screen and use the grid function to put the new widgets on screen, this way i can use buttons and functions with parameters whitout having to use lambda on the button, but i’m not sure if this is the most efficient way to do this, is there a better way to create, clear and use the widgets infomations on-screen on functions?
This is the class constructor:
class GUI:
def __init__(self):
#application:
self.window = tk.Tk()
#Labels:
self.screen_top_label = tk.Label(self.window)
self.client_label = tk.Label(self.window)
#....
#entries:
self.name_entry = tk.Entry(self.window)
self.email_entry = tk.Entry(self.window)
self.phone_entry = tk.Entry(self.window)
#...
(theres a lot more widgets but im just using this as an example)
and this would be the function that creates a screen:
def create_client_ui(self):
self.clear_screen()
self.window.title("Register Client")
self.screen_top_label.config(text="Enter Client Data")
self.screen_top_label.grid(row=0, column=0, sticky=tk.W, pady=5, padx=5)
self.name_label.config(text="Client Name: ")
self.name_label.grid(row=1, column=0, sticky=tk.W, pady=5, padx=5)
self.name_entry.grid(row=1,column=1, sticky=tk.W, pady=5, padx=5)
self.email_label.config(text="Client email: ")
self.email_label.grid(row=2, column=0, sticky=tk.W, pady=5, padx=5)
self.email_entry.grid(row=2, column=1, sticky=tk.W, pady=5, padx=5)
self.phone_label.config(text="Client Phone: ")
self.phone_label.grid(row=3, column=0, sticky=tk.W, pady=5, padx=5)
self.phone_entry.grid(row=3, column=1, sticky=tk.W, pady=5, padx=5)
self.main_action_button.config(text="Register Client", command=self.send_item)
self.main_action_button.grid(row=4, column=0, sticky=tk.W, pady=10, padx=10)
self.back_button.grid(row=0, column=2, sticky=tk.W, pady=10, padx=10)
Is this optimal or should i try another method?
Corvo Celestial is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.