Kivy第一个app

# --** 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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值