一组有用的Tkinter小部件。

belfrywidgets的Python项目详细描述


一组有用的tkinter小部件和巨型小部件。

此软件包包含:

折叠窗格:
可通过单击标签折叠的LabelFrame派生项。
标签按钮:
标签派生,可以像按钮一样单击,具有滚动和焦点。
标签笔记本:
提供Safari样式选项卡的笔记本,带有可选的关闭按钮 按标签。
向导:
带有prev/next/finish/cancel按钮的向导对话框,该对话框将继续 通过多个窗口小部件。
滚动列表框:
带有滚动条的列表框小部件,类似于ScrolledText小部件。
进度条:
圆形进度条,功能类似于tkinter.ttk.progress bar, 除了颜色在所有平台上都更容易控制。
工具提示:
将工具提示附加到小部件,因此将鼠标悬停在该小部件上将 显示一个小的工具提示消息。

折叠窗格

示例代码:

from belfrywidgets import CollapsiblePane

tk = Tk()
cp = CollapsiblePane(
    tk,
    text="Click Here to Collapse",
    visible=True,
    collapsible=True,
)
cp.pack(side=TOP, fill=BOTH, expand=1, padx=5, pady=5)
lbl1 = Label(cp.holder, text="This is a label.")
lbl2 = Label(cp.holder, text="This is another label.")
lbl1.pack(side=TOP)
lbl2.pack(side=TOP)
tk.mainloop()

标签按钮

示例代码:

from belfrywidgets import LabelButton
tk = Tk()
b1 = LabelButton(tk, text="Button 1", command=lambda: print("B1!"))
b2 = LabelButton(tk, text="Button 2", command=lambda: print("B2!"))
b1.pack(side=TOP, padx=20, pady=20)
b2.pack(side=TOP, padx=20, pady=20)
tk.mainloop()

选项卡式笔记本

示例代码:

from belfrywidgets import TabbedNoteBook

def _closeit(name):
    print("Close tab %s" % name)
    return True  # Return True to allow closing tab.

tk = Tk()
tnb = TabbedNoteBook(tk, width=640, height=480)
tnb.pack_propagate(False)  # Keep noteboox from shrinking to fit contents.
tnb.pack(side=TOP, fill=BOTH, expand=1)

pane1 = tnb.add_pane(
    'one', 'First Pane',
    closecommand=lambda: _closeit('one')
)
lbl1 = Label(pane1, text="This is a label.")
lbl1.pack(side=TOP, fill=BOTH, expand=1)

pane2 = tnb.add_pane(
    'two', 'Second Pane',
    closecommand=lambda: _closeit('two')
)
lbl2 = Label(pane2, text="This is a second label.")
lbl2.pack(side=TOP, fill=BOTH, expand=1)

pane3 = tnb.add_pane(
    'three', 'Third Pane',
    closecommand=lambda: _closeit('three')
)
lbl3 = Label(pane3, text="This is a third label.")
lbl3.pack(side=TOP, fill=BOTH, expand=1)

lbl = tnb.pane_label('two')
lbl.config(text="Tab 2")

tk.mainloop()

向导

示例代码:

from belfrywidgets import Wizard

root = Tk()
wiz = Wizard(
    width=640,
    height=480,
    cancelcommand=lambda: print("Cancel"),
    finishcommand=lambda: print("Finish"),
)

def disable_finish():
    wiz.set_finish_enabled(False)

def enable_finish():
    wiz.set_finish_enabled(True)

pane1 = wiz.add_pane('one', 'First', entrycommand=disable_finish)
lbl1 = Label(pane1, text="This is the first pane.")
lbl1.pack(side=TOP, fill=BOTH, expand=1)

pane2 = wiz.add_pane( 'two', 'Second')
lbl2 = Label(pane2, text="This is the second pane.")
lbl2.pack(side=TOP, fill=BOTH, expand=1)

pane3 = wiz.add_pane(
    'three', 'Third',
    entrycommand=enable_finish,
    prevcommand=disable_finish
)
lbl3 = Label(pane3, text="This is the third pane.")
lbl3.pack(side=TOP, fill=BOTH, expand=1)

# wiz.show_pane('two')
# wiz.del_pane('two')
# wiz.set_prev_enabled(True)
# wiz.set_next_enabled(True)

root.wm_withdraw()
root.wait_window(wiz)

滚动列表框

示例代码:

from belfrywidgets import Wizard

root = Tk()
lbox = ScrolledListbox(
    root,
    horiz_scroll=False,
    vert_scroll=True,
    width=30,
    height=15,
)
lbox.pack(side=TOP, fill=BOTH, expand=1)
for i in range(1,51):
    lbox.insert(END, "Item %d" % i)
tk.mainloop()

进度条

不确定模式示例代码:

from belfrywidgets import ProgressBar, INDETERMINATE

tk = Tk()
tk.config(background="#446")
pb = ProgressBar(
    tk, mode=INDETERMINATE,
    bordercolor="#446",
    foreground="red",
    background="cyan"
)
pb.pack(fill=BOTH, expand=1, padx=10, pady=10)
pb.start()
tk.after(20000, pb.stop)
tk.mainloop()

确定模式示例代码:

from belfrywidgets import ProgressBar, DETERMINATE

tk = Tk()
tk.config(background="#446")
v = DoubleVar()
v.set(0.0)
pb = ProgressBar(
    tk, mode=DETERMINATE,
    maximum=200,
    variable=v,
    bordercolor="#446",
    foreground="red",
    background="cyan"
)
pb.pack(fill=BOTH, expand=1, padx=10, pady=10)

def inc():
    v.set(v.get()+1)
    if v.get() < 200:
        tk.after(100, inc)

inc()
tk.mainloop()

工具提示

示例代码:

from belfrywidgets import ToolTip

tk = Tk()
ent = Entry(tk)
txt = Text(tk, borderwidth=2, relief="sunken")
ent.pack(side=TOP, padx=5, pady=5)
txt.pack(side=TOP, padx=5, pady=5)
txt.insert(END, "Tagged Text\n", "footag")
txt.insert(END, "Untagged Text\n")
ToolTip(ent, "This is an entry widget.")
ToolTip(txt, "This is a text widget.", tag="footag")
tk.mainloop()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java Webstart“javaws open”标志不适用于多个参数   java ArrayList声明和处理   获取数组中值的百分比(Java)   java将ArrayList转换为字符串以存储在共享首选项中   Java8Lambdas与泛型的结合使用   Scala数组到Java   如何使用java知道webcontainer的路径?   java使用“收集”和“合并”的组背后的算法是什么   java OSGi:在两个不同的包中具有相同的包路径   java混淆了swt画布。重画   java正则表达式,用于5位数逗号分隔的值,例如047000480004900   使用HttpClient显示非ASCI字符的java   水塔计算程序Java中球体体积的计算   java根据给定值调整框架中所有组件的大小   java Builder类中的其他方法(lombok注释)