Python_69-74节

from tkinter import *
master = Tk()
theLB = Listbox(master, selectmode=EXTENDED, height=11)#类似一个列表
theLB.pack()
for item in range(11):
    theLB.insert(END, item)
mainloop()
==============
from tkinter import *
root = Tk()
sb = scrollbar(root)
sb.pack(side=RIGHT, fill=Y) #在右侧,填充y轴,加一个滚动条
lb = Listbox(root, yscrollcommand=sb.set)
for i in range(1000):
    lb.insert(END, i)
lb.pack(side=LEFT, fill=BOTH)
sb.config(conmmand=lb.yview)#设置sb的属性
mainloop()
==============================
from tkinter import *
root = Tk()
s1 = Scale(root, from_=0, to=42, tickinterval=5, resolution=5, length=200)
s1.pack()
s2 = Scale(root, from_=0, to=200, tickinterval=10, resolution=10, length=600, orient=HORIZONTAL)
s2.pack()
def show():
    print(s1.get(), s2.get())
Button(root, text="获取位置", command=show).pack()
mainloop()
#checkbutton radiobutton 单选和多选
#listbox 多行文本
#frame LabelFrame多个组件构成一个框架
#scale 提供一个范围,让用户在里面选择一个确切的值
#scrollbar 提供一个滚动条
from tkinter import *
root = Tk()
text = Text(root, width=30, height=5)
text.pack()
text.insert(INSERT, "I love \n")
text.insert(END, "Fishcc.com")
def show():
    print("我被点了一下!")

b1 = Button(text, text="点我点我", command=show)
text.window_create(INSERT, window=b1)
mainloop()
===========================================
from tkinter import *
root = Tk()
text = Text(root, width=30, height=30)
text.pack()

photo = PhotoImage("file=fishc.gif")
def show():
    text.image_create(END, iamge=photo)#在text组件里创造一个图片的实例对象

b1 = Button(text, text="点我点我", command=show)
text.window_create(INSERT, window=b1)
mainloop()
==================================
text.insert(INSERT, "I love fishc")
text.mark_set("here", "1.2") #光标移到第一行 第2个位置,行从1开始,列从0开始。
text.insert("here", "插") #mark会记住插入的位置
text.insert("here", "入")
text.delete("1.0", END)#删掉附近的文本
==============================
text.insert(INSERT, "I love fishc")
text.mark_set("here", "1.2") #光标移到第一行 第2个位置,行从1开始,列从0开始。
text.mark_gravity("here", LEFT) #重心,默认插入为右边,改为左边
text.insert("here", "插") #mark会记住插入的位置
text.insert("here", "入")
==================================
from tkinter import *
root = Tk()
text = Text(root, width=30, height=5)
text.pack()
text.insert(INSERT, "I love fishc.com")
text.tag_add("tag1", "1.7", "1.12", "1.14")#创建一个tag
text.tag_config("tag1",background="yellow", foreground="red")#设置tag的属性
mainloop()
=====================================
from tkinter import *
root = Tk()
text = Text(root, width=30, height=5)
text.pack()
text.insert(INSERT, "I love fishc.com")
text.tag_add("tag1", "1.7", "1.12", "1.14")#创建一个tag
text.tag_add("tag2", "1.7", "1.12", "1.14")#创建一个tag
text.tag_config("tag1", background="yellow", foreground="red")#设置tag的属性
text.tag_config("tag2", foreground="blue")#前景色覆盖了上一个属性
mainloop()
==============================
from tkinter import *
root = Tk()
text = Text(root, width=30, height=5)
text.pack()
text.insert(INSERT, "I love fishc.com", ("tag2", "tag1"))
text.tag_lower("tag2")
text.tag_config("tag1", background="yellow", foreground="red")#设置tag的属性
text.tag_config("tag2", foreground="blue")#前景色覆盖了上一个属性
mainloop()
==============================
第71节
from tkinter import *
root = Tk()
w = Canvas(root, width=200, height=100)
w.pack()
line1 = w.create_line(0, 50, 200, 50, fill="yellow") 
line2 = w.create_line(100, 0, 100, 100, fill="red", dash=(4, 4)) 
rect1 = w.create_rectangle(50, 25, 150, 75, fill="blue") 
w.coords(line1, 0, 25, 200, 25)
w.itemconfig(rect1, fill="red")
w.delete(line2)
Button(root, text="输出全部", command=(lambda x=ALL:w.delete(x))).pack()
#冒号前面是参数,后面是返回值
mainloop()
=======================
from tkinter import *
root = Tk()
w.Canvas(root, width=200, height=100)
w.pack()
w.create_line(0, 0, 200, 100, fill="green", width=3)
w.create_line(200, 0, 0, 100, fill="green", width=3)
w.create_rectangle(40, 20, 160, 80, fill="green")
w.create_rectangle(60, 35, 135, 65, fill="yellow")
w.create_text(100, 50 ,text="FishC")
mainloop()
==========================
from tkinter import *
root = Tk()
w.Canvas(root, width=200, height=100)
w.pack()
w.create_oval(40, 20, 160, 80, fill="pink")#圆形是特色的椭圆
w.create_rectangle(40, 20, 160, 80, dash=(4, 4))
w.create_text(100, 50 ,text="FishC")
mainloop()
===============================
from tkinter import *
import math as m
root = Tk()
w = Canvas(root, width=200, height=100)
w.pack()
center_x = 100
center_y = 50
r = 50
points = [
#左上角
center_x - int(r * m.sin(2 * m.pi / 5)),
center_y - int(r * m.cos(2 * m.pi / 5)),
#右上角
center_x + int(r * m.sin(2 * m.pi / 5)),
center_y - int(r * m.cos(2 * m.pi / 5)),
#左下角
center_x - int(r * m.sin(2 * m.pi / 10)),
center_y + int(r * m.cos(2 * m.pi / 10)),
#顶点
center_x,
center_y-r,
#右下角
center_x + int(r * m.sin(2 * m.pi / 10)),
center_y + int(r * m.cos(2 * m.pi / 10)),
]

w.create_polygon(points, outline="green", fill="yellow")
#默认黑色填充,空字符串为透明
mainloop()
from tkinter import *
root = Tk()
w = Canvas(root, width=200, height=100)
w.pack()
def paint(event):
    x1, y1 = event.x - 1, event.y - 1
    x2, y2 = event.x + 1, event.y + 1
    w.create_oval(x1, y1, x2, y2, fill="red")
w.bind("<B1-Motion>", paint)
Label(root, text="请开始绘制吧").pack(side=BOTTOM)
mainloop()
===============================
from tkinter import *
root = Tk()
def callback():
    print("你好!")
menubar = Menu(root)
menubar.add_command(label="hello", command=callback)
menubar.add_command(label="quit", command=root.quit)
root.config(menu=menubar)
mainloop()
==================
from tkinter import *
root = Tk()
def callback():
    print("你好!")

menubar = Menu(root)
filemenu = Menu(menubar, tearoff=False)
filemenu.add_command(label="打开", command=callback)
filemenu.add_command(label="保存", command=callback)
filemenu.add_separator()
filemenu.add_command(label="退出", command=root.quit)
filemenu.add_cascade(label="文件", menu=filemenu)

editmenu = Menu(menubar, tearoff=False)
editmenu.add_command(label="剪切", command=callback)
editmenu.add_command(label="拷贝", command=callback)
editmenu.add_command(label="黏贴", command=callback)
editmenu.add_cascade(label="编辑", menu=editmenu)

root.config(menu=menubar)
mainloop()
==========================
from tkinter import *
root = Tk()
def callback():
    print("你好!")
menubar = Menu(root)
menubar.add_command(label="撤销", command=callback)
menubar.add_command(label="重做", command=root.quit)

frame = Frame(root, width=512, height=512)
frame.pack()
def popup(event):
    menubar.post(event.x_root, event.y_root)
frame.bind("<Button-3>", popup)
mainloop()
=========================
from tkinter import *
root = Tk()
def callback():
    print("你好!")

mb = Menubutton(root, text="点我", relief=RAISED)
mb.pack()
filemenu = Menu(mb, tearoff=False)
filemenu.add_command(label="打开", command=callback)
filemenu.add_command(label="保存", command=callback)
filemenu.add_separator()
filemenu.add_command(label="退出", command=root.quit)

mb.config(menu=filemenu)
mainloop()
=================
from tkinter import *
root = Tk()
variable = StringVar()
variable.set("one")
w = OptionMenu(root, variable, "one", "two", "three")
w.pack()
mainloop()
=================
from tkinter import *
root = Tk()
OPTIONS = ["California", "458", "FF", "123456"]
variable = StringVar()
variable.set(OPTIONS[0])
w = OptionMenu(root, variable, *OPTIONS)
w.pack()
mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王泽邦_bill

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值