I'm really new to tkinter and I want to experiment with using multiple windows in tkinter. I have borrowed the code from here: https://pythonprogramming.altervista.org/create-more-windows-with-tkinter/?doing_wp_cron=1645372524.8916330337524414062500 I am looking to be able to move the buttons from being just centred in the middle and at the top of the window but I am unsure of how to move the buttons in the window. I know how to move buttons normally outside of a class using pack() but I am unsure about how to do it within the class and this code. When I try to add attributes like side or fill, the window would appear but the button wouldn't. I have looked everywhere for a solution but I haven't found anything that suits my problem
Code:
import tkinter as tk
class Win1:
def __init__(self, master):
self.master = master
self.master.geometry("800x800")
self.frame = tk.Frame(self.master)
self.butnew("Click to open Window 2", "2", Win2)
self.butnew("Click to open Window 3", "3", Win3)
self.frame.pack()
def butnew(self, text, number, _class):
tk.Button(self.frame, text = text, command= lambda: self.new_window(number, _class)).pack()
def new_window(self, number, _class):
self.new = tk.Toplevel(self.master)
_class(self.new, number)
class Win2:
def __init__(self, master, number):
self.master = master
self.master.geometry("800x800+200+200")
self.frame = tk.Frame(self.master)
self.quit = tk.Button(self.frame, text = f"Quit this window n. {number}", command = self.close_window)
self.quit.pack()
self.frame.pack()
def close_window(self):
self.master.destroy()
class Win3:
def __init__(self, master, number):
self.master = master
self.master.geometry("800x800+200+200")
self.frame = tk.Frame(self.master)
self.quit = tk.Button(self.frame, text = f"Quit this window n. {number}", command = self.close_window)
self.quit.pack()
self.label = tk.Label(self.frame, text="THIS IS ONLY IN THE THIRD WINDOW")
self.label.pack()
self.frame.pack()
def close_window(self):
self.master.destroy()
root = tk.Tk()
app = Win1(root)
root.mainloop()