Python- GUI(Tkinter)
2017-08-16 18:11
218 查看
基本窗口
import tkinter as tk window = tk.Tk() window.title('my window') window.geometry('200x100') # 这里是窗口的内容 window.mainloop()
组件
#label l = tk.Label(window, text='OMG! this is TK!', # 标签的文字 bg='green', # 背景颜色 font=('Arial', 12), # 字体和字体大小 width=15, height=2 # 标签长宽 ) l.pack() # 固定窗口位置
#按钮加点击事件 var = tk.StringVar() # 这时文字变量储存器 l = tk.Label(window, textvariable=var, # 使用 textvariable 替换 text, 因为这个可以变化 bg='green', font=('Arial', 12), width=15, height=2) l.pack() on_hit = False # 默认初始状态为 False def hit_me(): global on_hit if on_hit == False: # 从 False 状态变成 True 状态 on_hit = True var.set('you hit me') # 设置标签的文字为 'you hit me' else: # 从 True 状态变成 False 状态 on_hit = False var.set('') # 设置 文字为空 b = tk.Button(window, text='hit me', # 显示在按钮上的文字 width=15, height=2, command=hit_me) # 点击按钮式执行的命令 b.pack() # 按钮位置
#登录窗口实例 import tkinter as tk window = tk.Tk() window.title('Welcome to Mofan Python') window.geometry('450x300') # welcome image canvas = tk.Canvas(window, height=200, width=500) image_file = tk.PhotoImage(file='welcome.gif') image = canvas.create_image(0,0, anchor='nw', image=image_file) canvas.pack(side='top') # user information tk.Label(window, text='User name: ').place(x=50, y= 150) tk.Label(window, text='Password: ').place(x=50, y= 190) var_usr_name = tk.StringVar() var_usr_name.set('example@python.com') entry_usr_name = tk.Entry(window, textvariable=var_usr_name) entry_usr_name.place(x=160, y=150) var_usr_pwd = tk.StringVar() entry_usr_pwd = tk.Entry(window, textvariable=var_usr_pwd, show='*') entry_usr_pwd.place(x=160, y=190) def usr_login(): pass def usr_sign_up(): pass # login and sign up button btn_login = tk.Button(window, text='Login', command=usr_login) btn_login.place(x=170, y=230) btn_sign_up = tk.Button(window, text='Sign up', command=usr_sign_up) btn_sign_up.place(x=270, y=230) window.mainloop()
相关文章推荐
- python tkinter GUI 程序简易实例
- Python3 初学实践案例(7)tkinter 入门 GUI 的密码生成程序
- Python GUI之tkinter概述
- 鱼c笔记——Python的GUI编程(一):接触Tkinter
- Tkinter 8.5 参考手册: a GUI for Python (五)4
- Python -- Gui编程 -- Tkinter的使用 -- 基本控件
- 树回归--python Tkinter库创建GUI(2)
- Python Tkinter GUI(一)简单小窗口
- python应用系列教程——python的GUI界面编程Tkinter全解
- 鱼c笔记——Python的GUI编程(十七):Tkinter的标准对话框模块messagebox 、filedialog 和 colorchooser
- Python3.4GUI Tkinter的使用
- Python GUI 之 TKinter(一)
- Python Tkinter制作GUI
- Tkinter 8.5 参考手册: a GUI for Python (五)5
- python学习之GUI(Tkinter)
- Python GUI——Tkinter~简单入门
- Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框
- Python3.5 tkinterGUI
- python 文件操作学习 Tkinter GUI
- Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Find/undo事件)——Jason niu