0
点赞
收藏
分享

微信扫一扫

python中Tkinter用法(二)


文章目录

  • ​​内容五​​
  • ​​内容六​​




内容五

from tkinter import *

master = Tk()

theLb = Listbox(master)
theLb.pack()

mainloop()

python中Tkinter用法(二)_ide



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用法(二)_单选_02



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用法(二)_python_03



from tkinter import *

root = Tk()

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

python中Tkinter用法(二)_ide_04



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用法(二)_ide_05



from tkinter import *

root = Tk()

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

mainloop()

python中Tkinter用法(二)_ide_06



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用法(二)_单选_07


python中Tkinter用法(二)_python_08



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用法(二)_ide_09





内容六

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用法(二)_python_10



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用法(二)_单选_11



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用法(二)_Text_12



举报

相关推荐

0 条评论