TKinter —— GUI in python 1. 装配使用

This blog intrudoce how to use Tkinter GUI in the python.

这篇Blog主要深入 Tkinter 的用法

 

Tkinter:

Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit, and is Python's de facto standard GUI. Tkinter is included with standard Linux, Microsoft Windows and Mac OS X installs of Python. The nameTkinter comes from Tk interface.


Tk 是一个开源的工具 用以 开发 GUI

Tk 有很多小工具交互 广泛的应用于 不同的主机应用, 比如 按钮 ,菜单, 窗口 ,输入

早在 90 年代, tk 的前身 就在 脚本语言 出现过 : tool command language (TCL)


 

Tkinter相关就不加以阐述 直接进入安装部分

 

Target: 目标 

--- 初用---

  • 1. 用4行code 建造一个可用的 GUI
  • 2. 自定义 GUI 的 大小
  • 3. 调控GUI 参数

 

 

——————————————————————————————————————————————初用

1. 导入

创造 GUI

#======================
# imports
#======================
import tkinter as tk        # Python 3: "t" lower-case

# Create instance
win = tk.Tk()   

# Add a title       
win.title("Python GUI")

#======================
# Start GUI
#======================
win.mainloop()

 结果如下:


2. 修改默认大小

#======================
# imports
#======================
import tkinter as tk

# Create instance
win = tk.Tk()   

# Add a title       
win.title("Python GUI")

#======================
# functions
#======================
def get_current_windows_size():
    win.update()                        # to get runtime size
    print('width  =', win.winfo_width())
    print('height =', win.winfo_height())

def increase_window_width():
    # min width can not be resized to less
    # default heigth can be
    win.minsize(width=300, height=1)    # 1 = default

#======================
# Start GUI
#======================
get_current_windows_size()
increase_window_width()
print()
get_current_windows_size()

win.mainloop()
  • win.update()  更新其他方程对这个window 做过的更改

  • minsize(w, h) 限制窗口最低尺寸 / 1 在这里面指默认

  • mainloop()  运行, 因为窗口可被用于执行动画 因此是在不停的执行 刷新的

这个概念会在TKinter —— GUI in python  4. 小组件 赋功能 中解释


3. 预防不被更改

生成的窗口不能用箭头 拖动去扩大或缩小

def increase_window_width():
    # min width can not be resized to less
    # default height can be
    win.minsize(width=300, height=1)    # 1 = default

    # disable resizing the GUI
    win.resizable(0,0)

 


异常简单的初始化 就完成了!!

更多的内容请移步 下一个教程

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值