gpt4 book ai didi

python - 名称错误 : Factory name not defined - Kivy

转载 作者:行者123 更新时间:2023-12-04 10:12:14 25 4
gpt4 key购买 nike

我收到错误

NameError: name 'Factory' is not defined



当我尝试在 kv 文件中导入 Factory 时。但是我已经在py文件中导入了。

下面是我的代码,

KV文件:
<MessagePopup>:
id: popup
auto_dismiss: False
title: "User Verification"
size_hint: None, None
size: 300,300
space_x: self.size[0]/6
space_y: self.size[1]/6
BoxLayout:
orientation: "vertical"
spacing: 20
padding: popup.space_x, popup.space_y
Label:
text: "Click to verify"
Button:
id:popup_phone
text:"Verify"
size_hint_y: 5.5
on_release:
Factory.PhonePopup().open()
<PhonePopup@Popup>:
id: "Phno_popup"
title: "Verify"
size_hint: None, None
size: 300,300
space_x: self.size[0]/6
space_y: self.size[1]/6
BoxLayout:
orientation: "vertical"
spacing: 20
padding: Phno_popup.space_x, Phno_popup.space_y
Label:
text:"Enter"
size_hint_y: 5.5
TextInput:
id: id_phno
size_hint_y: 5.5
multiline: False
Button:
text: "Verify"
size_hint_y: 5.5
on_press: root.id_verify()


py文件:

import mysql.connector
from kivy.app import App
from kivy.config import Config
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.textinput import TextInput
from kivy.factory import Factory

我是 kivy 的初学者。

最佳答案

您也需要在 kv 中导入 Factory。
将以下行添加到 .kv 的顶部文件:

#:import Factory kivy.factory.Factory

关于python - 名称错误 : Factory name not defined - Kivy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61269554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com