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
#1
I'm a newbie at python and coding in general. I am messing around with Tkinter, trying to understand it. Before I go any further can someone tell me if it's ok practice to create a class to initialise Toplevel() windows?

This is my code, please pull it to pieces:

from tkinter import *

class TopLevelWindow():
    def __init__(self, master, width, height):
        self.master = master
        self.master.geometry("%sx%s+100+100" % (width, height))
        self.master.title("Toplevel Window")


root = Tk()
top1 = Toplevel()
top2 = Toplevel()
TopLevelWindow(top1, "300", "300")
TopLevelWindow(top2, "500", "250")

root.mainloop()
This code works but I really don't know what is happening, I just throw a few keywords together until it worked.
Can someone explain what is happening here where I pas in master and then define self.master as master. Is it even ALLOWED to be a master?

def __init__(self, master, width, height):
    self.master = master
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter two windows instead of one jacksfrustration 7 886 Feb-08-2024, 06:18 PM
Last Post: deanhystad
  pass a variable between tkinter and toplevel windows janeik 10 2,361 Jan-24-2024, 06:44 AM
Last Post: Liliana
  Tkinter multiple windows in the same window tomro91 1 860 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  [Tkinter] Help create scrollbar in chatbot with tkinter on python fenec10 4 1,541 Aug-07-2023, 02:59 PM
Last Post: deanhystad
Lightbulb Using Tkinter With Concurrent.Futures / ThreadPoolExecutor Class AaronCatolico1 1 1,481 Dec-14-2022, 08:01 PM
Last Post: deanhystad
Bug [Tkinter] CanĀ“t create a class for frames ThomasFab 5 2,034 Sep-28-2022, 08:44 PM
Last Post: deanhystad
Lightbulb [Tkinter] Tkinter Class Import Module Issue AaronCatolico1 6 3,137 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,917 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Toplevel window menator01 5 3,075 Apr-18-2022, 06:01 PM
Last Post: menator01
  [Tkinter] Not able to get image as background in a Toplevel window finndude 4 3,926 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