Nov-18-2019, 07:04 PM
(This post was last modified: Nov-18-2019, 07:10 PM by Gribouillis.)
ta2909i Wrote:What is the best way for two modules to work but with one slave child module to have the ability to run functions in the master function?I think a simple way is to use classes and pass class instances as object parameters, for example
# parent.py import uipart class MusicPlayer: def play_music(self): ... if __name__ == '__main__': player = MusicPlayer() ui = uipart.Ui(player) while True: ...
# uipart.py class Ui: def __init__(self, player): self.player = player def spam(self): # call the parent's callback as a player instance's method self.player.play_music() ...