Python Forum
[Kivy] How do I reference a method in another class?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Kivy] How do I reference a method in another class?
#1
How do I reference a method in my BoxLayout class from my App class?

class ConjugationGame(BoxLayout):
    round = 1
    game_state = 0
    def change_game_state(self):
        if self.game_state > 4:
            self.game_state == 1
        else:
            self.game_state += 1


class ConjugationApp(App):
    def build(self):
        Window.bind(on_key_down=self.key_down)
        return ConjugationGame()

    def key_down(self, key, scancode=None, *_):
        if scancode == 281:  # PAGE_DOWN
            print("PAGE_DOWN pressed")
            ConjugationGame.change_game_state()
When I press Page Down, I get this error:

Quote:TypeError: change_game_state() missing 1 required positional argument: 'self'
Reply


Messages In This Thread
How do I reference a method in another class? - by Exsul1 - Feb-29-2020, 07:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TKinter Widget Attribute and Method Quick Reference zunebuggy 3 790 Oct-15-2023, 05:49 PM
Last Post: zunebuggy
  [PyQt] I get a name Name Error: when calling a method inside a class radoo 2 2,330 Jun-11-2020, 05:02 PM
Last Post: radoo
  [Tkinter] Issue with calling a Class/Method in GUI File Fre3k 3 2,949 Mar-08-2020, 12:35 PM
Last Post: Fre3k
  [Tkinter] Call a class method from another (Tk GUI) class? Marbelous 3 6,140 Jan-15-2020, 06:55 PM
Last Post: Marbelous
  [Tkinter] Class with text widget method AeranicusCascadia 3 7,739 Nov-14-2017, 11:33 PM
Last Post: AeranicusCascadia
  How to define a method in a class 1885 2 4,621 Oct-29-2017, 02:00 AM
Last Post: wavic
  [PyQt] How to put class method into new module? California 0 2,884 Jan-18-2017, 04:05 PM
Last Post: California

Forum Jump:

User Panel Messages

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