python中Tkinter用法(二)

文章目录

    • 内容五
    • 内容六





内容五

from tkinter import *

master = Tk()

theLb = Listbox(master)
theLb.pack()

mainloop()

python中Tkinter用法(二)_第1张图片


from tkinter import *

master = Tk()

theLb = Listbox(master)
theLb.pack()

for item in ["zhu", "猪", "huzhuzhu", "胡猪猪"]:
    theLb.insert(END, item)

theButton = Button(master, text="删除它",
                   command=lambda x=theLb:x.delete(ACTIVE))
theButton.pack()

mainloop()

python中Tkinter用法(二)_第2张图片


from tkinter import *

master = Tk()
# SINGLE单选,,,EXTENDED多选,,,
theLb = Listbox(master, selectmode=SINGLE, height=11)
theLb.pack()

for item in range(11):
    theLb.insert(END, item)

theButton = Button(master, text="删除它",
                   command=lambda x=theLb:x.delete(ACTIVE))
theButton.pack()

mainloop()

python中Tkinter用法(二)_第3张图片


from tkinter import *

root = Tk()

sb = Scrollbar(root)
sb.pack()
sb.pack(side=RIGHT, fill=Y)
mainloop()

python中Tkinter用法(二)_第4张图片


from tkinter import *

root = Tk()

sb = Scrollbar(root)
sb.pack()
sb.pack(side=RIGHT, fill=Y)

lb = Listbox(root, yscrollcommand=sb.set)

for i in range(1000):
    lb.insert(END, i)

lb.pack(side=LEFT, fill=BOTH)

sb.config(command=lb.yview)

mainloop()

python中Tkinter用法(二)_第5张图片


from tkinter import *

root = Tk()

Scale(root, from_=0, to=42).pack()
Scale(root, from_=0, to=200, orient=HORIZONTAL).pack()

mainloop()

python中Tkinter用法(二)_第6张图片


from tkinter import *

root = Tk()

s1 = Scale(root, from_=0, to=42)
s1.pack()

s2 = Scale(root, from_=0, to=200, orient=HORIZONTAL)
s2.pack()


def show():
    print(s1.get(), s2.get())


Button(root, text="获取位置",command=show).pack()

mainloop()

python中Tkinter用法(二)_第7张图片
在这里插入图片描述


from tkinter import *

root = Tk()

Scale(root, from_=0, to=42,
      tickinterval=5, resolution=5, length=200).pack()


Scale(root, from_=0, to=200,
      tickinterval=10, orient=HORIZONTAL, length=600).pack()

mainloop()

python中Tkinter用法(二)_第8张图片




内容六

from tkinter import *

root = Tk()

text = Text(root, width=30, height=2)
text.pack()

# INSERT是输入光标所在的位置
text.insert(INSERT, "I love \n")
text.insert(END, "FishC.com!")

mainloop()

python中Tkinter用法(二)_第9张图片


from tkinter import *

root = Tk()

text = Text(root, width=30, height=5)
text.pack()

# INSERT是输入光标所在的位置
text.insert(INSERT, "I love \n")
text.insert(END, "FishC.com!")


def show():
    print("我被点了")


b1 = Button(text, text="点我", command=show)
text.window_create(INSERT, window=b1)

mainloop()

python中Tkinter用法(二)_第10张图片


hotoImage(file="18.gif")


def show():
    text.image_create(END, image=photo)


b1 = Button(text, text="点我", command=show)
text.window_create(INSERT, window=b1)

mainloop()

python中Tkinter用法(二)_第11张图片





你可能感兴趣的:(python)