Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.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 如何使用self.username作为工具栏标题_Python_Python 3.x_Kivy_Kivy Language_Kivymd - Fatal编程技术网

Python 如何使用self.username作为工具栏标题

Python 如何使用self.username作为工具栏标题,python,python-3.x,kivy,kivy-language,kivymd,Python,Python 3.x,Kivy,Kivy Language,Kivymd,我想使用人们用来登录的用户名作为我的MDToolbar的标题。 有人能帮我吗。我使用生成器。所以我不知道我会怎么做 这是我的python代码 class GipApp(MDApp): def build(self): self.theme_cls.primary_palette = 'Blue' screen = Builder.load_string(screen_helper) self.username = "unknown

我想使用人们用来登录的用户名作为我的MDToolbar的标题。 有人能帮我吗。我使用生成器。所以我不知道我会怎么做

这是我的python代码

class GipApp(MDApp):
    def build(self):
        self.theme_cls.primary_palette = 'Blue'
        screen = Builder.load_string(screen_helper)
        self.username = "unknown"
        self.usernameKV = "unknown"
        return screen


    def verify(self, username, password):
        if username != "" and password != "":
            for row in MySqlNames:
                if row[0].strip() == username:
                    sql = "SELECT Password from ID191774_6itn1project7.Users where Username = %s "
                    mycursor.execute(sql, (username))
                    TestPassword = mycursor.fetchall()
                    for row3 in TestPassword:
                        if row3[0].strip() == password:
                            dialog = MDDialog(title="Login successful")
                            dialog.open()
                            self.username = username
                            GipApp.get_running_app().root.current = 'main'

                        if row3[0] != password:
                            dialog = MDDialog(title="Passwords is not correct.")
                            dialog.open()
        else:
            dialog = MDDialog(title="Fill in the empty text boxes")
            dialog.open()
我想在
verify()
中使用self.username的字符串值

这是我的kivy代码,其中希望使用用户名作为MDToolbar标题

<MainScreen>:
    canvas.before:
        Rectangle:
            pos: self.pos
            size: self.size
            source: 'mountains.jpg'
    name: 'main'
    NavigationLayout:
        ScreenManager:
            Screen:    
                orientation: 'vertical'
                MDToolbar:
                    title: "??????????"
                    left_action_items:[["menu",lambda x: nav_drawer.toggle_nav_drawer()]]
                    elevation :12
                    pos_hint:{"center_x": .5, "center_y": .95}
                MDRoundFlatButton:
                    text: 'Start Object identify here'
                    text_color:(1, 1, 1, 1)
                    size: 110, 110
                    on_release: app.Yolo()
                    pos_hint:{"center_x": .35, "center_y": 0.5}
                MDRoundFlatButton:
                    text: 'Face mask tracking'
                    text_color:(1, 1, 1, 1)
                    size: 110, 110
                    
                    pos_hint:{"center_x": .65, "center_y": 0.5}
                MDLabel:
                    text:"Press esc to stop."
                    halign:'center'
                    theme_text_color:'Custom'
                    text_color:(1, 1, 1, 1)
                    font_style:'Subtitle1'
                    pos_hint:{"center_x": .5, "center_y": 0.35}
                MDIconButton:
                    icon: "account"
                    pos_hint:{"center_x": .95, "center_y": .95}
                    user_font_size: "35sp"
                    on_press: root.manager.current = 'account'
:
在以下情况之前:
矩形:
pos:self.pos
大小:self.size
资料来源:“mountains.jpg”
名称:'main'
导航布局:
屏幕管理器:
屏幕:
方向:“垂直”
MDToolbar:
标题:“????????”
左键动作项:[[“菜单”,lambda x:nav_抽屉。切换导航抽屉()
立面图:12
pos_提示:{“center_x”:.5,“center_y”:.95}
MDRoundFlatButton:
文本:“在此处开始对象标识”
文字颜色:(1,1,1,1)
尺码:110110
发布时:app.Yolo()
pos_提示:{“center_x”:.35,“center_y”:0.5}
MDRoundFlatButton:
文本:“面罩跟踪”
文字颜色:(1,1,1,1)
尺码:110110
pos_提示:{“center_x”:.65,“center_y”:0.5}
MDLabel:
文本:“按esc键停止。”
哈利格:“中心”
主题\文本\颜色:'自定义'
文字颜色:(1,1,1,1)
字体样式:“字幕1”
pos_提示:{“center_x”:.5,“center_y”:0.35}
MDIconButton:
图标:“帐户”
pos_提示:{“center_x”:.95,“center_y”:.95}
用户字体大小:“35sp”
按:root.manager.current='account'

有人能帮我解决这个问题吗?

您需要为工具栏提供一个ID,然后您就可以访问它的属性并在python中更改标题

下面是一个简单的演示,演示了单击按钮时工具栏标题的更改

from kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
MDFloatLayout:
    MDToolbar:
        title: "MDToolbar"
        pos_hint: {"top":1}
        id: toolbar


    MDRaisedButton:
        text: "Click"
        pos_hint: {"center_x":.5,"center_y":.5}
        on_release: app.change()
'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def change(self):
        self.root.ids.toolbar.title = "Custom Title"

Test().run()