鱼C论坛

 找回密码
 立即注册
查看: 1804|回复: 4

[作品展示] tkinter 元件

[复制链接]
发表于 2022-8-10 19:55:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
tkinter 元件
tkinter 有很多元件,有时也会忘了名字 ,为了方便查找,所以做了这个图,元件代码如下(只有基本参数,如果完整的其它参数可以让元件的功能更加完善,这里的代码只是简单带过):
tkinter 元件.jpg
from tkinter import *


root = Tk()
root.title("tkinter 的元件 - by 傻眼貓咪 - FishC")

labelFrame = [
    LabelFrame(root, text = "Button", padx = 40, pady = 40), LabelFrame(root, text = "Canvas", padx = 40, pady = 40), LabelFrame(root, text = "Checkbutton"),
    LabelFrame(root, text = "Entry", padx = 40, pady = 40), LabelFrame(root, bg = "grey", text = "Frame", padx = 40, pady = 40), LabelFrame(root, text = "Label", padx = 40, pady = 40),
    LabelFrame(root, text = "Listbox", padx = 40, pady = 40), LabelFrame(root, text = "Menubutton", padx = 40, pady = 40), LabelFrame(root, text = "Message", padx = 40, pady = 40),
    LabelFrame(root, text = "Radiobutton", padx = 40, pady = 40), LabelFrame(root, text = "Scale", padx = 40, pady = 40),
    LabelFrame(root, text = "Scrollbar", padx = 40, pady = 40), LabelFrame(root, text = "Spinbox", padx = 40, pady = 40),
    LabelFrame(root, text = "Text", padx = 40, pady = 40), LabelFrame(root, text = "PanedWindow", padx = 40, pady = 40, width = 40, height = 40, bg = "#FFFFFF")
    ]

for n, frame in enumerate(labelFrame):
    r, c = divmod(n, 5)
    frame.grid(row = r, column = c)

buttons = [Button(labelFrame[0], text = str(n + 1), padx = 15, pady = 15) for n in range(9)]
for n, button in enumerate(buttons):
    r, c = divmod(n, 3)
    buttons[n].grid(row = r, column = c)

canvas = Canvas(labelFrame[1], bg = "pink", width = 20, height = 20).pack()

checkButtons = [Checkbutton(labelFrame[2], text = chr(n + 65)) for n in range(5)]
for n, button in enumerate(checkButtons):
    checkButtons[n].grid(row = n)

entry = Entry(labelFrame[3], borderwidth = 5).pack()

frame = Frame(labelFrame[4], bg = "pink", width = 25, height = 25).pack()

labels = [Label(labelFrame[5], text = f"this is Label {n + 1}") for n in range(5)]
for n, button in enumerate(labels):
    labels[n].grid(row = n)

listbox = Listbox(labelFrame[6])
arr = ["one", "two", "three", "four", "five"]
for n, word in enumerate(arr):
    listbox.insert(n, word)
listbox.pack()

menubutton = Menubutton(labelFrame[7], text = "this is menu", relief = RAISED)
menubutton.menu = Menu(menubutton)
menubutton["menu"] = menubutton.menu

var = [IntVar() for _ in range(5)]
for n, word in enumerate(arr):
    menubutton.menu.add_checkbutton(label = word, variable = var[n])

menubutton.pack()

message = Message(labelFrame[8], text = "this is a message").pack()

v1 = StringVar(labelFrame[9], "R1")
v2 = StringVar(labelFrame[9], "R2")
valuesA = {f"RadioButton {n}" : str(n) for n in range(1, 6)}
valuesB = {f"RadioButton {chr(n + 65)}" : str(n + 1) for n in range(3)}

for n, (txt, val) in enumerate(valuesA.items()):
    Radiobutton(labelFrame[9], text = txt, variable = v1, value = val, indicator = 0).grid(row = n, column = 0)

for n, (txt, val) in enumerate(valuesB.items()):
    Radiobutton(labelFrame[9], text = txt, variable = v2, value = val).grid(row = n, column = 1)

scales = [Scale(labelFrame[10], orient = HORIZONTAL), Scale(labelFrame[10])]

for n, scale in enumerate(scales):
    scale.grid(row = n)

scrollbar = Scrollbar(labelFrame[11])
scrollbar.pack(side = RIGHT, fill = Y)
arr = Listbox(labelFrame[11], yscrollcommand = scrollbar.set)
for n in range(100):
    arr.insert(END, f"This is line {n}")
arr.pack(side = LEFT, fill = BOTH)
scrollbar.config(command = arr.yview)

spinbox = Spinbox(labelFrame[12], from_= 0, to = 100).pack()

text = Text(labelFrame[13], width = 10, height = 7)

text.insert(INSERT, "A B C D E F G H I J K L M ")
text.insert(END, "N O P Q R S T U V W X Y Z")
text.pack()

text.tag_add("posA", "1.0", "1.4")
text.tag_add("posB", "1.8", "1.13")
text.tag_config("posA", background = "yellow", foreground = "blue")
text.tag_config("posB", background = "black", foreground = "green")

panelwindow = PanedWindow(labelFrame[14], bg = "#000000", width = 20, height = 20).pack()

root.mainloop()

评分

参与人数 5荣誉 +14 鱼币 +15 贡献 +9 收起 理由
JasonChencCjj + 1 鱼C有你更精彩^_^
python爱好者. + 5 + 5 + 3 鱼C有你更精彩^_^
青出于蓝 + 3 + 3 + 3
Passepartout + 1 + 1 感谢楼主无私奉献!
柿子饼同学 + 5 + 5 + 3

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-8-10 20:50:57 | 显示全部楼层
高级高级
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2022-8-11 07:42:52 | 显示全部楼层
好用
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-8-11 08:40:02 | 显示全部楼层
厉害!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-8-11 08:44:43 | 显示全部楼层
好用
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-16 18:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表