Python Forum
how to edited Tkinter Toplevel from main form?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to edited Tkinter Toplevel from main form?
#6
It doesn't matter if you call Toplevel(), Toplevel(None) or Toplevel(root). The default value for "master" is None. When master is none, the root window is assigned to be the window's master.

This is why one window programs can get away with not passing a master argument when making widgets. tk.Label(text="I am a label") adds a label to the root window, root being the default value for master. This should be avoided because it inevitably leads to confusion when you write a program with two windows or a custom dialog, and the widgets for your second window appear in the root. As seen here:
import tkinter as tk


class BadWindow(tk.Toplevel):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        tk.Label(text="I've been a very bad window!").pack()


class GoodWindow(tk.Toplevel):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        tk.Label(self, text="I follow the rules!").pack()


root = tk.Tk()
tk.Button(root, text="Make a good window.", command=GoodWindow).pack(padx=50, pady=10)
tk.Button(root, text="Make a bad window.", command=BadWindow).pack(padx=50, pady=10)
root.mainloop()
When the program makes a BadWindow the label is added to the root window because no master is specified.
Reply


Messages In This Thread
RE: how to edited Tkinter Toplevel from main form? - by deanhystad - Apr-24-2024, 05:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  QUIZ GUI Form_When admin panel is open, main quiz form is getting freeze Uday 4 842 Aug-25-2023, 08:24 PM
Last Post: deanhystad
  Prevent a PDF from being edited using Python? PythonNPC 1 2,396 May-05-2020, 09:04 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020