Python Forum
[Tkinter] Can´t create a class for frames
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Can´t create a class for frames
#4
(Sep-27-2022, 03:49 PM)deanhystad Wrote: Just a small change to make a much better better solution:
class CustomFrames(tk.Frame):
     def __init__(self, parent, name, *args, **kwargs):
         super().__init__(parent, *args, **kwargs)
         parent.add(self, text=name)
 
 frame01Start=CustomFrames(notebook1, "Start")
Your frame class should not have to know about frame01Start and the tab name should not be limited to "Start". These should be passed as arguments to the __init__() method.

*args and **kwargs allow passing additional arguments to Frame.__init__(). CustomFrames doesn't have to know anything about these arguments, it just passes them along to the Frame.__init__() method.


perfect. Thank you!
Reply


Messages In This Thread
Can´t create a class for frames - by ThomasFab - Sep-27-2022, 12:30 PM
RE: Can´t create a class for frames - by ThomasFab - Sep-27-2022, 01:50 PM
RE: Can´t create a class for frames - by ThomasFab - Sep-28-2022, 05:46 AM
RE: Can´t create a class for frames - by ThomasFab - Sep-28-2022, 09:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Class function does not create command button Heyjoe 2 2,335 Aug-22-2020, 08:06 PM
Last Post: Heyjoe
  Using a class to create instances of Tkinter Toplevel() windows nortski 2 11,083 Mar-27-2018, 11:44 AM
Last Post: nortski

Forum Jump:

User Panel Messages

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