Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python =connection.cursor() cursor.execute(“从workoutData中选择*,其中活动=‘抱石’和难度=?”,(难度,) self.rows=str(cursor.fetchall()) root\u widget=Build_Python_Kivy - Fatal编程技术网

Python =connection.cursor() cursor.execute(“从workoutData中选择*,其中活动=‘抱石’和难度=?”,(难度,) self.rows=str(cursor.fetchall()) root\u widget=Build

Python =connection.cursor() cursor.execute(“从workoutData中选择*,其中活动=‘抱石’和难度=?”,(难度,) self.rows=str(cursor.fetchall()) root\u widget=Build,python,kivy,Python,Kivy,=connection.cursor() cursor.execute(“从workoutData中选择*,其中活动=‘抱石’和难度=?”,(难度,) self.rows=str(cursor.fetchall()) root\u widget=Builder.load\u字符串(“”) 屏幕管理器: 主屏幕: 名称:“主屏幕” 难度:抱石。从难度(自我难度)加载难度 Urec_设施: 名称:'urecFac' 冒险家名录: 名称:'AdventureDirectory' BouldingDir

=connection.cursor() cursor.execute(“从workoutData中选择*,其中活动=‘抱石’和难度=?”,(难度,) self.rows=str(cursor.fetchall()) root\u widget=Builder.load\u字符串(“”) 屏幕管理器: 主屏幕: 名称:“主屏幕” 难度:抱石。从难度(自我难度)加载难度 Urec_设施: 名称:'urecFac' 冒险家名录: 名称:'AdventureDirectory' BouldingDirectory: id:抱石 难点:“初学者” 名称:'BouldingDirectory' : 在以下情况之前: 矩形: pos:self.pos 大小:self.size 来源:“mainScreenImage.png” 标签: 文本:“选择您的困难” 字体大小:50 颜色:(0.9,0.8,0,1) 背景颜色:(0,0,0,0) pos_提示:{“x”:0,“y”:0.20} 按钮: 文字:“初学者” 字体大小:30 大小提示:0.2,0.2 颜色:(0.9,0.8,0,1) 背景颜色:(0,0,0,0) pos_提示:{“x”:0.16,“y”:0.1} 发布时: root.comble=“初学者” app.root.current='urecFac' 按钮: 正文:“中级” 字体大小:30 大小提示:0.2,0.2 颜色:(0.9,0.8,0,1) 背景颜色:(0,0,0,0) pos_提示:{“x”:0.41,“y”:0.1} 发布时: root.comble=“中级” app.root.current='urecFac' 按钮: 文本:“高级” 字体大小:30 大小提示:0.2,0.2 颜色:(0.9,0.8,0,1) 背景颜色:(0,0,0,0) pos_提示:{“x”:0.66,“y”:0.1} 发布时: root.comble=“高级” app.root.current='urecFac' : 盒子布局: 方向:“垂直” 按钮: 文字:“冒险中心” 字体大小:50 颜色:(0.9,0.8,0,1) 背景正常:“adventureCenterImage.jpg” 发布时:app.root.current=“AdventureDirectory” 按钮: 背景图片正常:“mainScreenImage.png” 文本:“返回” 字体大小:50 颜色:(0.9,0.8,0,1) 发布时:app.root.current=“mainScreen” : 盒子布局: 方向:“垂直” 按钮: 正文:“抱石” 字体大小:50 颜色:(0.9,0.8,0,1) 发布时: app.root.current=“BouldingDirectory” 按钮: 文本:“返回” 字体大小:50 颜色:(0.9,0.8,0,1) 发布时: app.root.current=“urecFac” : 盒子布局: 方向:“垂直” 标签: 文本:root.rows 文本大小:(root.width-175),无 按钮: 文本:“返回” 字体大小:50 颜色:(0.9,0.8,0,1) 背景颜色:(0,0,0,1) 发布时: app.root.current=“AdventureDirectory” """) 类屏幕管理器RAPP(应用程序): def生成(自): 返回root\u小部件 如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': ScreenManagerApp().run()
尽管我仍然不知道如何更改变量的字符串以使我的SQL工作。发布时:#将困难变量设置为字符串“Intermediate”app.root.current='urecFac',您是否尝试在所述函数中声明全局变量。如果是,您能给我们看一下功能代码吗?@Weekday您的解决方案将无法工作,因为它不会通知更改,此外,不建议使用全局变量:我已经在函数中声明了它,它可以工作,但它不会更改字符串,因为on_release调用没有方法分配给变量。只需在声明全局变量后在函数中进行简单赋值就行了。我已经在函数中声明了它,它可以工作,但它不会更改字符串字符串,因为on_release调用没有方法分配给变量。@shroomss什么字符串没有改变值?变量没有改变它的值,因为我不知道如何通过main中的on_release调用来改变它_Screen@ShrooMsss我不是基维专家,但是我认为你只需要在发布时定义
方法,添加
全局难度
,然后根据需要编辑变量。因此,在我的主屏幕类中,我创建了一个名为switch的函数,参数为text。该函数不执行难度=文本的操作。然后,在按钮的on_释放中,我调用此函数,参数为(“中间”),但我得到一个错误“takes 1 positional argument but 2 wave”,你知道为什么吗?谢谢。这似乎对更改变量很有效,但由于某种原因,当我转到我的BouldingDirectory屏幕时,我数据库中的数据不再显示,为什么会出现此问题?@shroomss你可以共享你的.db,我已经测试过了,它工作正常。Nvm,我让它工作了,非常感谢。非常感激。
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()
class BoulderingDirectory(Screen):
    global difficult
    ...
class BoulderingDirectory(Screen):
    global difficult
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
from kivy.properties import StringProperty
import sqlite3

class Main_Screen(Screen):
   difficult = StringProperty()

class Urec_facilities(Screen):
   pass

class AdventureDirectory(Screen):
   pass

class BoulderingDirectory(Screen):
    rows = StringProperty("")

    def load_from_difficult(self, difficult):
        connection = sqlite3.connect("workoutData.db")
        cursor = connection.cursor()
        cursor.execute("SELECT * FROM workoutData WHERE Activity = 'Bouldering' and Difficulty = ?", (difficult,))
        self.rows = str(cursor.fetchall())

root_widget = Builder.load_string("""
ScreenManager:
    Main_Screen:
        name: 'mainScreen'
        on_difficult: bouldering.load_from_difficult(self.difficult)
    Urec_facilities:
        name: 'urecFac'
    AdventureDirectory:
        name: 'AdventureDirectory'
    BoulderingDirectory:
        id: bouldering
        difficult: 'Beginner'
        name: 'BoulderingDirectory'

<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:
            root.difficult =  "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:
            root.difficult = "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:
            root.difficult = "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"

""")

class ScreenManagerApp(App):
    def build(self):
        return root_widget

if __name__ == '__main__':
    ScreenManagerApp().run()