python tkinter chk
视频过程中的练习, 可以在python2.7下运行. 001: hello,world: 1
2
3
4
5
6
from Tkinter import Label, Tk root = Tk()
thelabel = Label(root, text="This is too easy")
thelabel.pack()
root.mainloop() 002: Button pack布局 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from Tkinter import * root = Tk() topFrame = Frame(root)
topFrame.pack()
bottomFrame = Frame(root)
bottomFrame.pack(side=BOTTOM) button1 = Button(topFrame, text="Button 1", fg="red")
button2 = Button(topFrame, text="Button 2", fg="blue")
button3 = Button(topFrame, text="Button 3", fg="green")
button4 = Button(bottomFrame, text="Button 4", fg="purple") button1.pack(side=LEFT)
button2.pack(side=LEFT)
button3.pack(side=LEFT)
button4.pack(side=BOTTOM) root.mainloop() 003: Label和pack布局 1
2
3
4
5
6
7
8
9
10
11
12
13
from Tkinter import * root = Tk() one = Label(root, text="one", bg="red", fg="white")
two = Label(root, text="two", bg="green", fg="black")
three = Label(root, text="three", bg="blue", fg="white") one.pack()
two.pack(fill=X)
three.pack(side=LEFT, fill=Y) root.mainloop() 004: grid布局. 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from Tkinter import * root = Tk() label_1 = Label(root, text="Name")
label_2 = Label(root, text="Password")
entry_1 = Entry(root)
entry_2 = Entry(root) label_1.grid(row=0)
label_2.grid(row=1)
entry_1.grid(row=0, column=1)
entry_2.grid(row=1, column=1) root.mainloop() 005: grid布局 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from Tkinter import * root = Tk() label_1 = Label(root, text="Name")
label_2 = Label(root, text="Password")
entry_1 = Entry(root)
entry_2 = Entry(root) label_1.grid(row=0, sticky=E)
label_2.grid(row=1, sticky=E)
entry_1.grid(row=0, column=1)
entry_2.grid(row=1, column=1) c = Checkbutton(root, text="Keep me logged in")
c.grid(columnspan=2) root.mainloop() 006: Button和事件 1
2
3
4
5
6
7
8
9
10
11
from Tkinter import * root = Tk() def printName():
print("Chello my name is Bucky!") button_1 = Button(root, text="Print my name", command=printName)
button_1.pack() root.mainloop() 007: 绑定事件: 左键,中键,右键 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#coding:utf8
from Tkinter import * root = Tk() def printName(event):
print("Chello my name is Bucky!") button_1 = Button(root, text="Print my name")
'''
<Button-1> 鼠标左键
<Button-2> 鼠标中键
<Button-3> 鼠标右键
'''
button_1.bind("<Button-1>", printName)
button_1.pack() root.mainloop() 008: 绑定事件: 左键,中键,右键 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from Tkinter import * root = Tk() def leftClick(event):
print "left" def middleClick(event):
print "middle" def rightClick(event):
print "right" frame = Frame(root, width=300, height=250)
frame.bind("<Button-1>", leftClick)
frame.bind("<Button-2>", middleClick)
frame.bind("<Button-3>", rightClick)
frame.pack() root.mainloop() 009: Python GUI with Tkinter-8-Using Classes 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# -*- coding:utf-8 -*-
'''
Python GUI with Tkinter-8-Using Classes
'''
from Tkinter import * class BuckysButtons:
def __init__(self, master):
frame = Frame(master)
frame.pack() self.printButton = Button(frame, text="Print Message", command=self.printMessage)
self.printButton.pack(side=LEFT) self.quitButton = Button(frame, text="Quit", command=frame.quit)
self.quitButton.pack(side=LEFT) def printMessage(self):
print "Wow, this actually worked!" root = Tk()
b = BuckysButtons(root)
root.mainloop() 010: Python GUI with Tkinter-9-Creating Drop Down Menus 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
# -*- coding:utf-8 -*-
'''
Python GUI with Tkinter-9-Creating Drop Down Menus
'''
from Tkinter import * def doNothing():
print("ok ok I won't...") root = Tk() menu = Menu(root)
root.config(menu=menu) subMenu = Menu(menu)
menu.add_cascade(label="File", menu=subMenu)
subMenu.add_command(label="New Project...", command=doNothing)
subMenu.add_command(label="New...", command=doNothing)
subMenu.add_separator()
subMenu.add_command(label="Exit", command=doNothing) editMenu = Menu(menu)
menu.add_cascade(label="Edit", menu=editMenu)
editMenu.add_command(label="Redo", command=doNothing) root.mainloop() 011: Python GUI with Tkinter-10-Creating a Toolbar 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
31
32
33
34
35
36
37
38
# -*- coding:utf-8 -*-
'''
Python GUI with Tkinter-10-Creating a Toolbar
'''
from Tkinter import * def doNothing():
print("ok ok I won't...") root = Tk() # ***** Main Menu *****
menu = Menu(root)
root.config(menu=menu) subMenu = Menu(menu)
menu.add_cascade(label="File", menu=subMenu)
subMenu.add_command(label="New Project...", command=doNothing)
subMenu.add_command(label="New...", command=doNothing)
subMenu.add_separator()
subMenu.add_command(label="Exit", command=doNothing) editMenu = Menu(menu)
menu.add_cascade(label="Edit", menu=editMenu)
editMenu.add_command(label="Redo", command=doNothing) # ***** Toolbar ***** toolbar = Frame(root, bg="blue") insertBtn = Button(toolbar, text="Insert Image", command=doNothing)
insertBtn.pack(side=LEFT, padx=2, pady=2)
printBtn = Button(toolbar, text="Print", command=doNothing)
printBtn.pack(side=LEFT, padx=2, pady=2) toolbar.pack(side=TOP, fill=X) root.mainloop() 012: Python GUI with Tkinter-11-Adding the Status Bar 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
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding:utf-8 -*-
'''
Python GUI with Tkinter-11-Adding the Status Bar
'''
from Tkinter import * def doNothing():
print("ok ok I won't...") root = Tk() # ***** Main Menu *****
menu = Menu(root)
root.config(menu=menu) subMenu = Menu(menu)
menu.add_cascade(label="File", menu=subMenu)
subMenu.add_command(label="New Project...", command=doNothing)
subMenu.add_command(label="New...", command=doNothing)
subMenu.add_separator()
subMenu.add_command(label="Exit", command=doNothing) editMenu = Menu(menu)
menu.add_cascade(label="Edit", menu=editMenu)
editMenu.add_command(label="Redo", command=doNothing) # ***** Toolbar ***** toolbar = Frame(root, bg="blue") insertBtn = Button(toolbar, text="Insert Image", command=doNothing)
insertBtn.pack(side=LEFT, padx=2, pady=2)
printBtn = Button(toolbar, text="Print", command=doNothing)
printBtn.pack(side=LEFT, padx=2, pady=2) toolbar.pack(side=TOP, fill=X) # ***** Status Bar ***** status = Label(root, text="Preparing to do nothing...", bd=1, relief=SUNKEN, anchor=W)
status.pack(side=BOTTOM, fill=X) root.mainloop() 013: Python GUI with Tkinter-12-Messagebox 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# -*- coding:utf-8 -*-
'''
Python GUI with Tkinter-12-Messagebox
How to create a message box with tkinter?
http://stackoverflow.com/questions/1052420/how-to-create-a-message-box-with-tkinter
'''
from Tkinter import *
import tkMessageBox root = Tk()
tkMessageBox.showinfo("Window Title", "Monkeys can live up to 300 years.")
msg = tkMessageBox answer = msg.askquestion("Question1", "Do you like silly faces?") if answer == 'yes':
print(' 8===D~') root.mainloop() 014: Python GUI with Tkinter-13-Shapes and Graphics 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# -*- coding:utf-8 -*-
'''
Python GUI with Tkinter-13-Shapes and Graphics
'''
from Tkinter import * root = Tk() canvas = Canvas(root, width=200, height=100)
canvas.pack() blackLine = canvas.create_line(0, 0, 200, 50)
redLine = canvas.create_line(0, 100, 200, 50, fill="red")
greenBox = canvas.create_rectangle(25, 25, 130, 60, fill="green") # canvas.delete(redLine)
canvas.delete(ALL) root.mainloop() 015: Python GUI with Tkinter-14-Images and Icons 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
# -*- coding:utf-8 -*-
'''
Python GUI with Tkinter-14-Images and Icons
(1.1)在这个例子中遇到问题"_tkinter.TclError: couldn't recognize data in image file"
(1.2)http://stackoverflow.com/questions/27599311/tkinter-photoimage-doesnt-not-support-png-image
(1.3)http://effbot.org/tkinterbook/photoimage.htm
(1.4)解决办法参考上面的链接. 引入 "from PIL import Image, ImageTk"
---------------
(2)中文目录要加 u"..."
'''
from Tkinter import *
from PIL import Image, ImageTk root = Tk() imgList = ["image001.png", "kaola.jpg", u"考拉.jpg"]
print(imgList[-1])
image = Image.open(imgList[-1])
# photo = PhotoImage(file="image001.png")
photo = ImageTk.PhotoImage(image) label = Label(root, image=photo)
label.pack() root.mainloop()
python tkinter chk的更多相关文章
- Python Tkinter基础控件入门实例
分享一个Python Tkinter基础控件用法的入门例子,包括窗口的显示.显示内置图片.弹出窗口.菜单等. 例子,Python Tkinter基础控件的用法 # -*- coding: utf-8 ...
- Python Tkinter 学习成果:点歌软件music
笔者工作业余时间也没什么爱好,社交圈子也小,主要娱乐就是背着自己带电瓶的卖唱音响到住地附近找个人多的位置唱唱KtV. 硬件上点歌就用笔记本电脑,歌曲都是网上下载的mkv格式的含有两个音轨的视频.因此点 ...
- Python Tkinter Entry(文本框)
Python学习记录--关于Tkinter Entry(文本框)的选项.方法说明,以及一些示例. 属性(Options) background(bg) borderwidth(bd) cursor e ...
- python tkinter Listbox用法
python tkinter组件的Listbox的用法,见下面代码的演示: from tkinter import * root=Tk() v=StringVar() #Listbox与变量绑定' l ...
- python Tkinter之Button
Button小部件是一个标准的Tkinter的部件,用于实现各种按钮.按钮可以包含文本或图像,您可以调用Python函数或方法用于每个按钮. Tkinter的按钮被按下时,会自动调用该函数或方法. 该 ...
- python gui tkinter快速入门教程 | python tkinter tutorial
本文首发于个人博客https://kezunlin.me/post/d5c57f56/,欢迎阅读最新内容! python tkinter tutorial Guide main ui messageb ...
- Python tkinter模块弹出窗口及传值回到主窗口操作详解
这篇文章主要介绍了Python tkinter模块弹出窗口及传值回到主窗口操作,结合实例形式分析了Python使用tkinter模块实现的弹出窗口及参数传递相关操作技巧,需要的朋友可以参考下 本文实例 ...
- Python Tkinter 文本框(Entry)
Python Tkinter 文本框用来让用户输入一行文本字符串. 你如果需要输入多行文本,可以使用 Text 组件. 你如果需要显示一行或多行文本且不允许用户修改,你可以使用 Label 组件. 语 ...
- Python Tkinter 窗口创建与布局
做界面,首先需要创建一个窗口,Python Tkinter创建窗口很简单:(注意,Tkinter的包名因Python的版本不同存在差异,有两种:Tkinter和tkinter,读者若发现程序不能运行, ...
随机推荐
- 利用itext导出PDF的小例子
我这边使用的jar包: itext-2.1.7.jar itextasian-1.5.2.jar 代码,简单的小例子,导出pdf: PdfService.java: package com.cy.se ...
- 观察者模式之一:java实现观察者模式
<观察者模式之一:java实现观察者模式> <观察者模式之二:JDK自带的观察者模式> 1.初步认识 观察者模式的定义: 在对象之间定义了一对多的依赖,这样一来,当一个对象改变 ...
- [转][Java]尝试解决Java多行字符串的编辑问题
转自:https://blog.csdn.net/jiuwuerliu/article/details/51207045 参考了:https://www.v2ex.com/amp/t/445522 除 ...
- 文档碎片及xml讲解
1.将数据渲染到页面的几种方式 1.字符串拼接 2.dom循环 3.模板 4.文档碎片 字符串拼接: 优势:只进行一次dom回流 缺点:原有的dom事件会消失 案例分析:原有list中有3个li,并且 ...
- jquery.autocomplete 搜索文字提示
function GetJobTitle(obj) { $(obj).autocomplete("GetJobTitle.ashx", { max: 12, //列表里的条目数 m ...
- MySQL 之管理脚本
Mysql中查看每个IP的连接数 ) as ip , count(*) from information_schema.processlist group by ip;
- sas 数据集导出到excel
PROC EXPORT DATA= Loan.BOM_FILENAME_2 OUTFILE= "D:\output.xls" DBMS=EXCEL REPLAC ...
- ZooKeeper系列(6):ZooKeeper机制架构
一.ZooKeeper权限管理机制 1.1 权限管理ACL(Access Control List) ZooKeeper 的权限管理亦即ACL 控制功能,使用ACL来对Znode进行访问控制.ACL的 ...
- python多进程与服务器并发
进程 什么是进程 进程:正在进行的一个过程或者说一个任务.而负责执行任务则是cpu. 进程与程序的区别 程序仅仅只是一堆代码而已,而进程指的是程序的运行过程. 并发与并行 无论是并行还是并发,在用户看 ...
- tips:Java的Random类和Random函数
tips:Java的Random类和Random函数! 随机数是一个很有趣的东西,在java中可以通过下面这2种方法得到: (1)Random类: Random类是java.util.Random这个 ...