我对基维语还不熟悉。我正在尝试建立一个简单的程序来在两个屏幕之间切换。第一个屏幕包含一个按钮,松开按钮将切换到第二个屏幕。点击第二个屏幕上的按钮将进入第一个屏幕。你知道吗
我面临的问题: 1按钮放在角落里,我希望它的大小是全窗口,但它很小
<ChatGUI>:
MainManager:
MainWindow:
SecondWindow:
<MainWindow>:
name: "main"
Button:
text:"to second window"
on_release:app.root.current="second"
<SecondWindow>:
name: "second"
Button:
text:"back to main"
on_release:app.root.current="main"
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView
from kivy.graphics import Rectangle, Color, Canvas
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.core.window import Window
from kivy.config import Config
from kivy.lang import Builder
class ChatGUI(Widget):
present=Builder.load_file("Chat.kv")
class MainWindow(Screen):
pass
class SecondWindow(Screen):
pass
class MainManager(ScreenManager):
pass
class ChatApp(App):
def build(self):
return ChatGUI()
if __name__=="__main__":
ChatApp().run()
我在youtube教程上练习。你知道吗
我已经检查了许多来自堆栈溢出的代码,但在我的代码中没有发现问题。你知道吗
输出应显示占整个窗口大小的按钮,释放时应切换到下一个屏幕。你知道吗
你能告诉我有什么问题吗。你知道吗
问题1-小部件@左下角&窗口未满?你知道吗
根本原因
Kivy Widget » Default values
问题2-释放按钮屏幕未切换?你知道吗
根本原因
当按下按钮时,屏幕没有切换,因为应用程序的根不是ScreenManager。你知道吗
解决方案
解决这些问题有两种选择。你知道吗
选项1-使用布局作为根目录
此选项使用BoxLayout作为根,并需要以下增强。A Layout可以是
GridLayout
、BoxLayout
、FloatLayout
等Py文件
Builder.load_file(...)
替换present = Builder.load_file(...)
Builder.load_file(...)
移出class ChatGUI()
并添加pass
kv文件
id: sm
,MainManager:
app.root.ids.sm.current
替换app.root.current
片段-选项1
main1.py
main1.kv
选项2-使用ScreenManager作为根目录
此选项需要以下增强功能:
Py文件
from kivy.uix.widget import Widget
class ChatGUI()
return MainManager()
替换return ChatGUI()
Builder.load_file(...)
替换present = Builder.load_file(...)
kv文件
片段-选项2
main2.py
main2.kv
您不需要在
Widget
内添加ScreenManager
。 所以呢在python文件中
在kv文件中 为了让你的榜样发挥作用,我只改变了这些。你知道吗
你知道吗千伏你知道吗
你知道吗主.py你知道吗
相关问题 更多 >
编程相关推荐