0
我是基維新手。當在主屏幕(登錄屏幕)上單擊'註冊'按鈕時,我想切換到另一個屏幕(註冊屏幕)。這裏是Python代碼:屏幕開關不會發生在按鈕點擊kivy
import kivy
kivy.require('1.9.0')
import ConfigParser
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.screenmanager import Screen, ScreenManager
Window.size = (700, 550)
class LoginPage(Screen):
def switch_screen(*args):
global sm
print "i am in login and will switch to signup"
sm.current = 'signup'
class SignUp(Screen):
print "signup screen"
pass
sm = ScreenManager()
sm.add_widget(LoginPage(name="login"))
sm.add_widget(SignUp(name="signup"))
class Test(App):
icon = "C:\Users\shru\Desktop\download.jpg"
title = "Member Login"
def build(self):
return sm
if __name__ == "__main__":
Test().run()
這裏是.kv代碼
<LoginPage>:
canvas:
Rectangle:
source: "C:\Users\shru\Desktop\m.jpg"
size: self.size
Widget:
Button:
size: 90,35
pos: 380,200
font_size:15
background_color: (1,1,1,0.3)
text: "SignUp"
on_press: root.switch_screen()
<SignUp>:
canvas:
Rectangle:
source: "C:\Users\shru\Desktop\m.jpg"
size: self.size
Widget:
Button:
size: 90,35
pos: 380,200
font_size:15
background_color: (1,1,1,0.3)
text: "hello"
這對執行返回空白屏幕。難道我做錯了什麼?
謝謝