Python图形界面Tkinter的使用详解2018-10-22 · 大约 900 个字 · 预计 4 分钟 读完PythonPython · Tkinter本文参考自莫烦python视频:https://morvanzhou.github.io/tutorials/python-basic/tkinter/导入模块 1 import Tkinter #注意python 3.0改为了tkinter 或者直接这样导入1 from TKinter import * 最简单的界面 注意我的python版本是:2.7.151 2 3 4 5 6 7 #!/usr/bin/python # -*- coding: UTF-8 -*- from Tkinter import * top = Tk() top.mainloop() Label和Button 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #!/usr/bin/python # -*- coding: UTF-8 -*- #3.0版本请使用 import tkinter as tk import Tkinter as tk window = tk.Tk() window.title('我的窗口') #添加标题 window.geometry('400x200') #设置window大小 v = tk.StringVar(None, 'i am a label', None) #文字变量存储器 #width=15表示15个字符宽度,heiht=2表示2个字符高度,如果直接设置文本可以用text='labeltext' lable = tk.Label(window, textvariable=v, bg='green', font=('Arial', 12), width=20, height=2) lable.pack() on_hit = False def click_me(): #按钮点击处理方法 global on_hit if on_hit == False: on_hit = True v.set('clicked you ...') else: on_hit = False v.set('') button = tk.Button(window, text="click me", width=15, height=2, command=click_me) button.pack() window.mainloop() 阅读更多
Python两个案例练习2016-11-10 · 大约 1400 个字 · 预计 7 分钟 读完PythonPython · Tkinter · 打包 · 发布项目介绍 Python官方LOGO项目是一个python入门的案例代码,可以帮助你通过实践来更好的学习python项目地址:https://gitlab.com/lxqxsyu/PythonDemos阅读更多