Python Forum
Generating menus with classes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generating menus with classes
#3
In the code below, test() creates an instance of class test. It doesn't create a variable to reference the instance, but it still creates a test object.
class test :
    def __init__ (self) :
        print ('I am ALIVE!')
 
test()
The only difference between "test()" and "a = test()" is that "a = test()" creates a variable named "a" in the current scope and assigns it to reference the object return by test(). With or without a variable to reference it the object is created the same.

The same is true for HeyJoe's example. This code in Main.__init__ creates an instance of FirstMenu. Then the FirstMenu.__init__() create instances of SecondMenu which in turn creates an instance of ThirdMenu. There are no variables that reference the created objects, but the objects are still created. You should think about reworking the code. I don't think it is a good idea cascading code like that, and you obviously don't understand how it works. That is never a good thing.

I don't know where you got the idea that you need instances to use classes. A class can consist completely of class attributes and class variables and act just like a module.
Reply


Messages In This Thread
Generating menus with classes - by Heyjoe - Feb-11-2021, 01:48 AM
RE: Generating menus with classes - by BashBedlam - Feb-11-2021, 02:41 AM
RE: Generating menus with classes - by deanhystad - Feb-11-2021, 05:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Which is best GUI for drop down menus and calculations Chuck_Norwich 2 2,117 Sep-27-2019, 05:59 PM
Last Post: Chuck_Norwich
  Binding functions to Menus in tkinter?? Mocap 1 2,487 Jul-23-2019, 01:37 AM
Last Post: Larz60+
  Menus and icons changed after upgrade blackclover 0 1,961 May-11-2018, 08:14 PM
Last Post: blackclover

Forum Jump:

User Panel Messages

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