栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python


“”"
My first application
“”"

import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW


class HelloWorld(toga.App):

    def startup(self):
        """
        Construct and show the Toga application.

        Usually, you would add your application to a main content box.
        We then create a main window (with a name matching the app), and
        show the main window.
        """
        # main_box = toga.Box()
        #
        # self.main_window = toga.MainWindow(title=self.formal_name)
        # self.main_window.content = main_box
        # self.main_window.show()
        #############################################
        main_box = toga.Box(style=Pack(direction=COLUMN))
        name_label = toga.Label('姓名: ', style=Pack(padding=(0, 5)))
        self.name_input = toga.TextInput(style=Pack(flex=1))

        name_box = toga.Box(style=Pack(direction=ROW, padding=5))
        name_box.add(name_label)
        name_box.add(self.name_input)

        button = toga.Button('打招呼', on_press=self.say_hello, style=Pack(padding=5))

        main_box.add(name_box)
        main_box.add(button)

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()

    def say_hello(self, widget):
        if self.name_input.value:
            name = self.name_input.value
        else:
            name = 'stranger'

        self.main_window.info_dialog(
            'Hello, {}'.format(name),
            'Hi there!'
        )

    def say_hello4(self, widget):#弹出一个坑框
        self.main_window.info_dialog(
            'Hello, {}'.format(self.name_input.value),
            'Hi there!'
        )

    def say_hello2(self, widget): #print
        print("Hello", self.name_input.value)

    def say_hello1(self):
        strinfo = "请输入您的姓名~~"
        print(self.name_input.value)
        # if self.name_input.value:
        #     strinfo = f"你好,{self.name_input.value}!n欢迎您。"
        #     self.main_window.info_dialog(strinfo, '')

def main():
    return HelloWorld()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/589024.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号