My program is failing because I'm not correctly referring to a particular widget. The root widget is a ScreenManager (MainInterface). It has a couple screens. To one of them, game_screen, I add a progress bar, “pb” (in create_puzzle). That works.
But when I try to increment the value of the progress bar (in time_left_update), I get: “AttributeError: ‘Screen’ object has no attribute ‘pb’.
I understand (I think) that pb will not be part of the ids dictionary, but I thought the way I refer to it in the time_left_update function should work. It doesn’t. Nor does “MainInterface.game_screen.pb”.
Final note: If I add the progress bar in the kv file, things work (except that the last line, where I try to remove it, does not work). I’m adding it in the Python code instead, however, because I need to repeatedly create and remove the progress bar.
I would be grateful if someone could straighten me out.
class MainInterface(ScreenManager):
def __init__(self, **kwargs):
super(MainInterface, self).__init__(**kwargs)
(doing other things here)...
#Note: these functions are not part of the MainInterface class.
def create_puzzle(w,*largs):
Do some things here…
pb = ProgressBar(size_hint = (.33, .05), pos_hint = {'x': .33, 'y': .61}, max = 360)
main.ids.game_screen.add_widget(pb)
event = Clock.schedule_interval(time_left_update, 1/6)
def time_left_update(self,*largs):
main.ids.game_screen.pb.value += 1
# line above causes AttributeError: 'Screen' object has no attribute 'pb'
if main.ids.game_screen.pb.value == 60
remove_pb()
def remove_pb(self):
event.cancel()
main.ids.game_screen.pb.value = 0
main.ids.game_screen.remove_widget(main.ids.game_screen.pb)
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
main.ids.game_screen.add_widget(pb)
Bill,
Thanks for your help. I don’t see my mistake as reflecting ignorance of Python (though my knowledge isn’t great--hence the name I've chosen) but rather an insufficient understanding of Kivy. I don’t see that I’m passing pb as a parameter to a function. If one adds a widget to a parent in the kv file, then that widget can be referenced anywhere in the program, within any function or method. Why, then, I’m wondering, is the same not true when you add a widget to a parent (here pb to game_screen) in the Python code?
But this is not globally available. It is only accessible to the class in which you define it. 'root' in this case refers to this class. So, its difficult to give general advice as this will depend on how you have setup your class structure.
@GmooIt's difficult to help when you add on to post with a long history and a lot to read. If you have an issue, please create a new post with a title that accurately describes the issue and ideally, code we can run that shows the issue.Thnaks
--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/oWNFhkw4VAA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.