我想讓這個按鈕工作,並不能找出什麼是錯的。 我真的可以使用一些幫助,因爲我是新的基維。當我運行代碼時,彈出按鈕,但是當你點擊它時,什麼都不會發生。爲什麼它不工作?無法獲取按鈕在基維工作
順便說一句,我知道一旦你到了下一頁,什麼都不會發生,但現在我只想到那裏。
這裏是完整的代碼和kv文件。
import kivy
kivy.require('1.9.1')
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
from kivy.uix.button import Button
class StartScreen(Widget):
def __init__(self, **kwargs):
super(StartScreen,self).__init__(**kwargs)
self.StartGame = Button(text="Start Game")
self.StartGame.bind(on_press=self.on_press)
self.add_widget(self.StartGame)
def on_press(self,instance):
return LoginScreen()
class LoginScreen(GridLayout):
def __init__(self, **kwargs):
super(LoginScreen,self).__init__(**kwargs)
self.cols = 2
class MyApp(App):
def build(self):
return StartScreen()
if __name__ == '__main__':
MyApp().run()
KV文件
#:kivy 1.9.1
<StartScreen>:
Label:
font_size: 120
center_x: root.width/2
top: root.top - 100
text: "Starfire"
<LoginScreen>
f_username: username
f_password: password
GridLayout:
rows: 2
padding: 5
spacing: 5
Label:
text: "User Name:"
TextInput:
id: username
Label:
text: 'Password'
TextInput:
id: password
password: True