I'm working on an program that is suppose to be an assistant for people that go to my local gym. Though I'm having trouble with a global variable difficult
to change its string value. I want to be able to press any of the Buttons in main_Screen
and have the string of the difficult
change. Therefore in the BoulderingDirectory
class it can preform the corresponding SQL for my database holding the exercises.
Note: I've cut off a majority of the code because there are multiple sections in the gym and I'm just focusing on this section because it applies exactly the same to other sections.
screen_manager = ScreenManager()
global difficult
difficult = "Beginner"
class ScreenManagerApp(App):
def build(self):
return screen_manager
class MyScreenManager(ScreenManager):
pass
class main_Screen(Screen):
pass
class urec_facilities(Screen):
pass
class AdventureDirectory(Screen):
pass
class BoulderingDirectory(Screen):
connection = sqlite3.connect("workoutData.db")
cursor = connection.cursor()
if (difficult == "Beginner"):
cursor.execute("SELECT * FROM workoutData WHERE Activity =
'Bouldering' and Difficulty = 'Beginner'")
elif(difficult == "Intermediate"):
cursor.execute("SELECT * FROM workoutData WHERE Activity =
'Bouldering' and Difficulty = 'Intermediate'")
else:
cursor.execute("SELECT * FROM workoutData WHERE Activity =
'Bouldering' and Difficulty = 'Advanced'")
rows = StringProperty(str(cursor.fetchall()))
root_widget = Builder.load_string("""
<main_Screen>:
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: "mainScreenImage.png"
Label:
text: "Select your dificulty"
font_size: 50
color: (0.9,0.8,0,1)
background_color: (0,0,0,0)
pos_hint: {"x": 0, "y": 0.20}
Button:
text: 'Beginner'
font_size: 30
size_hint: 0.2,0.2
color: (0.9,0.8,0,1)
background_color: (0,0,0,0)
pos_hint: {"x": 0.16, "y": 0.1}
on_release:
#set the difficult variable to a string "Beginner"
app.root.current = 'urecFac'
Button:
text: 'Intermediate'
font_size: 30
size_hint: 0.2,0.2
color: (0.9,0.8,0,1)
background_color: (0,0,0,0)
pos_hint: {"x": 0.41, "y": 0.1}
on_release:
#set the difficult variable to a string "Intermediate"
app.root.current = 'urecFac'
Button:
text: 'Advanced'
font_size: 30
size_hint: 0.2,0.2
color: (0.9,0.8,0,1)
background_color: (0,0,0,0)
pos_hint: {"x": 0.66, "y": 0.1}
on_release:
#set the difficult variable to a string "Advanced"
app.root.current = 'urecFac'
<urec_facilities>:
BoxLayout:
orientation: "vertical"
Button:
text: "Adventure Center"
font_size: 50
color: (0.9,0.8,0,1)
background_normal: "adventureCenterImage.jpg"
on_release: app.root.current = "AdventureDirectory"
Button:
background_normal: "mainScreenImage.png"
text: "Back"
font_size: 50
color: (0.9,0.8,0,1)
on_release: app.root.current = "mainScreen"
<AdventureDirectory>:
BoxLayout:
orientation: "vertical"
Button:
text: "Bouldering"
font_size: 50
color: (0.9,0.8,0,1)
on_release:
app.root.current = "BoulderingDirectory"
Button:
text: "Go back"
font_size: 50
color: (0.9,0.8,0,1)
on_release:
app.root.current = "urecFac"
<BoulderingDirectory>:
BoxLayout:
orientation: "vertical"
Label:
text: root.rows
text_size: (root.width - 175), None
Button:
text: "Go back"
font_size: 50
color: (0.9,0.8,0,1)
background_color: (0,0,0,1)
on_release:
app.root.current = "AdventureDirectory"
""")
screen_manager.add_widget(main_Screen(name = "mainScreen"))
screen_manager.add_widget(urec_facilities(name = "urecFac"))
screen_manager.add_widget(AdventureDirectory(name = "AdventureDirectory"))
screen_manager.add_widget(BoulderingDirectory(name = "BoulderingDirectory"))
ScreenManagerApp().run()