# --** coding=utf-8 **--
from kivy.app import App
from kivy.core.text import LabelBase
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
# 将中文字体存放在某一个目录下,建议使用相对路径
# resource_add_path(os.path.abspath("./data/fonts"))
# 替换掉默认字体
LabelBase.register("Roboto", "msyh.ttc")
Window.set_icon('bashu.png')
class LoginScreen(BoxLayout):
def __init__(self, **kwargs):
super(LoginScreen, self).__init__(**kwargs)
# 设置背景
Window.clearcolor = (0.533, 0.878, 0.878, 1)
self.orientation = "vertical"
print(Window.height, self.width)
self.padding = [10, 10, 20, Window.height / 2]
self.spacing = 10
row_layout1 = BoxLayout(orientation="horizontal", size_hint=(1, .2))
row_layout2 = BoxLayout(orientation="horizontal", size_hint=(1, .2))
register_label = Label(text='注册码:', size_hint=(.2, .5), color=(2.25, 2.25, 2.25, 1))
license_label = Label(text='license:', size_hint=(.2, .5), color=(2.25, 2.25, 2.25, 1))
self.username = TextInput(hint_text='Enter your register code', font_size=18, size_hint=(.8, .5))
self.licence_str = TextInput(hint_text='display your licence', font_size=18, size_hint=(.8, .5), readonly=True)
self.bt = Button(text='生成', on_release=self.release_button, background_color=(2.55, 1.4, 0, 1),
size_hint=(.3, .1), pos_hint={'center_x': .5, 'center_y': .5})
self.bt.bind(on_press=self.press_button)
row_layout1.add_widget(register_label)
row_layout1.add_widget(self.username)
row_layout2.add_widget(license_label)
row_layout2.add_widget(self.licence_str)
self.add_widget(row_layout1)
self.add_widget(row_layout2)
self.add_widget(self.bt)
def press_button(self, arg):
# 按下按钮触发事件的回调函数
print('press_button is running')
def release_button(self, arg):
# 按下按钮并释放时触发事件的回调函数
print('release_button is running')
self.licence_str.text = '更新后的内容'
class LicenseApp(App):
def build(self):
return LoginScreen()
if __name__ == '__main__':
LicenseApp().run()
Kivy第一个app
最新推荐文章于 2024-07-18 20:05:25 发布