Python Forum
Getting a variable from one class to another class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a variable from one class to another class
#3
example:
class control:
    def __init__(self):
        zz = class1().parrot()
        c2 = class2().display_it(zz)

# or you can do it this way:
#     def __init__(self):
#         zz = class1()
#         val = zz.parrot()
#         c2 = class2()
#         c2.display(val)

class class1:
    def __init__(self):
        pass

    def parrot(self):
        return "He's Resting"

class class2:
    def __init__(self):
        pass

    def display_it(self, what):
        print(what)

if __name__ == '__main__':
    control()
results:
Output:
He's Resting
Reply


Messages In This Thread
RE: Getting a variable from one class to another class - by Larz60+ - Apr-25-2020, 09:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Video [PyQt] Get a executable file (.exe) from a .py file add a promoted class in a QWidget MiguelonReyes 0 725 Oct-17-2023, 11:43 PM
Last Post: MiguelonReyes
  [Tkinter] Take the variable of a cursor class delcencen 2 1,248 Feb-13-2023, 05:19 AM
Last Post: deanhystad
Lightbulb Using Tkinter With Concurrent.Futures / ThreadPoolExecutor Class AaronCatolico1 1 1,535 Dec-14-2022, 08:01 PM
Last Post: deanhystad
  [PyQt] CustomSortFilterProxyModel Class Using hasantr 2 1,300 Dec-02-2022, 01:57 PM
Last Post: hasantr
Bug [Tkinter] CanĀ“t create a class for frames ThomasFab 5 2,193 Sep-28-2022, 08:44 PM
Last Post: deanhystad
Lightbulb [Tkinter] Tkinter Class Import Module Issue AaronCatolico1 6 3,296 Sep-06-2022, 03:37 PM
Last Post: AaronCatolico1
  [Tkinter] define entry via class on a loop drSlump 9 3,562 Oct-27-2021, 05:01 PM
Last Post: deanhystad
  [Kivy] Acces atributes from a button defined in a class inside the .kv Tomli 2 2,167 Jun-10-2021, 01:05 AM
Last Post: Tomli
  [Tkinter] Modify Class on Button Click KDog 4 4,052 May-11-2021, 08:43 PM
Last Post: KDog
Question [PyQt] Need help with class composition / multiple inheritance / polymorphism (?) Alfalfa 4 3,218 May-11-2021, 12:55 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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