Python Forum
Using a class to create instances of Tkinter Toplevel() windows
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using a class to create instances of Tkinter Toplevel() windows
#3
(Mar-27-2018, 11:12 AM)Larz60+ Wrote: self is an instance of itself, in your case TopLevelWindow
when you call __init__, you are passing top1 which is an instance of TopLevel, width of 300, and height of 300.

If you passed root instead of top1, there would only be one window.
you can also 'hide' the root window with root.withdraw()

Toplevel creates a new 'root like' window in addition to root

Once top1 is passed to TopLevelWindow, it becomes self.master or TopLevelWindow.master, but it's still the same instance of top1

Then you create yet another instance of TopLevelWindow passing top2 as master

you could of also instantiated TopLevelWindow this way, which may explain a bit more:
TopLevelWindow(master=top1, width="300", height="300")
I try to do this by default, but when cranking out code, often miss doing it. It explains what's what with a single glance.

Hi Larz, thank you very much for the explanation. I think the main thing that's important here is that this seems a legitimate way of creating multi toplevel windows without breaking anything else in Python haha

I can now move forward with my project.

Big Grin
Reply


Messages In This Thread
RE: Using a class to create instances of Tkinter Toplevel() windows - by nortski - Mar-27-2018, 11:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter two windows instead of one jacksfrustration 7 778 Feb-08-2024, 06:18 PM
Last Post: deanhystad
  pass a variable between tkinter and toplevel windows janeik 10 2,142 Jan-24-2024, 06:44 AM
Last Post: Liliana
  Tkinter multiple windows in the same window tomro91 1 790 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  [Tkinter] Help create scrollbar in chatbot with tkinter on python fenec10 4 1,432 Aug-07-2023, 02:59 PM
Last Post: deanhystad
Lightbulb Using Tkinter With Concurrent.Futures / ThreadPoolExecutor Class AaronCatolico1 1 1,420 Dec-14-2022, 08:01 PM
Last Post: deanhystad
Bug [Tkinter] CanĀ“t create a class for frames ThomasFab 5 1,944 Sep-28-2022, 08:44 PM
Last Post: deanhystad
Lightbulb [Tkinter] Tkinter Class Import Module Issue AaronCatolico1 6 2,974 Sep-06-2022, 03:37 PM
Last Post: AaronCatolico1
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,834 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Toplevel window menator01 5 2,987 Apr-18-2022, 06:01 PM
Last Post: menator01
  [Tkinter] Not able to get image as background in a Toplevel window finndude 4 3,840 Jan-07-2022, 10:10 PM
Last Post: finndude

Forum Jump:

User Panel Messages

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