热门

最新

红包

立Flag

投票

同城

我的

发布
jackchuanqi
传奇开心果编程 Python领域优质创作者
1 年前
truejackchuanqi

标签

使用Label组件可以创建一个显示文本的标签。以下是创建一个Label组件的代码

import toga

def build(app):

label = toga.Label('Hello, world!', style=Pack(padding=50))

return toga.MainWindow(title=app.name, size=(640, 480)).with_content(

toga.Box(children=[label], style=Pack(direction=COLUMN))

)

if __name__ == '__main__':

app = toga.App('My Label App')

app.startup = build

app.main_loop()

按钮

可以使用Button组件创建一个按钮,以便用户可以与应用程序交互。以下是创建一个Button组件的代码:

import to

def button_handler(widget):

print('Button pressed')

def build(app):

button = toga.Button('Click me!', on_press=button_handler)

return toga.MainWindow(title=app.name, size=(640, 480)).with_content(

toga.Box(children=[button], style=Pack(direction=COLUMN, padding=50))

)

if __name__ == '__main__':

app = toga.App('My Button App')

app.startup = build

app.main_loop()

码友杂谈区
川味小厨(铁路新村东街店)
CSDN App 扫码分享
分享
2
3
打赏
  • 复制链接
  • 举报
下一条:
努力努力再努力,我要成为万人迷
立即登录