I'm trying to let a button show a table in a new window and add a button to that window to destroy itself. The main problem is that the table shows up in the wrong window. Thanks for help.
I tried to do it myself, but everything I tried doesn't work.
import tkinter as tk class MainWindow(tk.Frame): counter = 0 def __init__(self, *args, **kwargs): tk.Frame.__init__(self, *args, **kwargs) self.button = tk.Button(self, text="Create new window", command=self.create_window) self.button.grid(padx = 5, pady = 5, row = 1, column = 3) def create_window(self): height = 2 width = 3 numberA=0 achievs = ["1", "2", "3", "4", "5", "6"] self.counter += 1 t = tk.Toplevel(self) t.wm_title("Window #%s" % self.counter) for i in range(height): #Rows for j in range(width): #Columns t = tk.Label(text=achievs[numberA], relief=tk.RIDGE) t.grid(row=i, column=j) numberA = numberA + 1 t.mainloop if __name__ == "__main__": root = tk.Tk() main = MainWindow(root) main.grid(row=4, column=5, padx=5, pady=25) root.mainloop()
As said the table should show in the toplevel window and if possible there should be a button to destroy the toplevel window (I probably can do that part myself tough).