博客
关于我
Python GUI tkinter库 自学21
阅读量:280 次
发布时间:2019-03-01

本文共 871 字,大约阅读时间需要 2 分钟。

简单对话框与通用消息框的使用示例

简单对话框

  • title表示窗口标题
  • prompt是提示信息
  • kw为命名参数,可设置各种选项
  • initialvalue为初始值
  • minvalue为最小值
  • maxvalue为最大值
函数名 说明
askfloat(title, prompt, **kw) 用于获取浮点数输入
askinteger(title, prompt, **kw) 用于获取整数输入
askstring(title, prompt, **kw) 用于获取字符串输入
示例代码:
from tkinter.simpledialog import * window = Tk() window.geometry("500x200")

def test1():a = askinteger(title="输入年龄", prompt="请输入年龄", initialvalue=18, minvalue=1, maxvalue=150)show["text"] = a

Button(window, text="你多大了?", command=test1).pack()show = Label(window, width=10, height=5, bg="green")show.pack()

window.mainloop()

通用消息框

示例代码:
from tkinter import * from tkinter.messagebox import *

window = Tk()window.geometry("500x200")

a = showinfo(title="学习", message="你会成功的!")print(a)

window.mainloop()

ttk子模块(简要介绍)

以上代码示例展示了如何在Tkinter应用程序中使用简单对话框和通用消息框功能。通过合理配置参数,开发者可以根据需求实现多种用户交互场景。此外,Tkinter的ttk子模块提供了丰富的组件和布局选项,能够进一步提升应用程序的用户体验。

转载地址:http://zkho.baihongyu.com/

你可能感兴趣的文章
QueryDict和模型表知识补充
查看>>
Querybase 使用与安装教程
查看>>
Playwright与Selenium的对比:谁是更适合你的自动化测试工具?
查看>>
PLC、DCS、SCADA的选型
查看>>
PLC中的电子凸轮的简单介绍
查看>>
PLC发展详解-ChatGPT4o作答+匹尔西
查看>>
PLC探针有什么用
查看>>
PLC接线详解
查看>>
PLC数组的使用(西门子)
查看>>
Quarzt定时调度任务
查看>>
PLC结构体(西门子)
查看>>
PLC编程语言ST文本语法的常用数据类型及变量
查看>>
PLC通讯方式
查看>>
Please install 'webpack-cli' in addition to webpack itself to use the CLI
查看>>
Ploly Dash,更新一个Dash应用程序JJJA上的实时人物
查看>>
Ploly烛台的定制颜色
查看>>
Ploly:如何在Excel中嵌入完全交互的Ploly图形?
查看>>
plotloss记录
查看>>
Plotly (Python) 子图:填充构面和共享图例
查看>>
Plotly 中的行悬停文本
查看>>