Inhaltsverzeichnis
1. Was ist ttkbootstrap?
2. Installationsschritte
3. Beginnen Sie mit der Verwendung von
Heim Backend-Entwicklung Python-Tutorial So verwenden Sie Python ttkbootstrap

So verwenden Sie Python ttkbootstrap

Apr 19, 2023 pm 04:55 PM
python

1. Was ist ttkbootstrap?

ttkbootstrap ist eine Schnittstellenverschönerungsbibliothek, die auf Tkinter basiert. Mit diesem Tool können Sie ein Tkinter-Desktopprogramm ähnlich dem Front-End-Bootstrap-Stil entwickeln

So verwenden Sie Python ttkbootstrap

2. Installationsschritte

Installationsbefehl: pip install ttkbootstrap

3. Beginnen Sie mit der Verwendung von

First. Eine kurze Einführung in die Instanziierung zum Erstellen von Anwendungsfenstern.

import ttkbootstrap as ttk
#实例化创建应用程序窗口,其实大部分命令与tkinter相似
root = ttk.Window(
        title="窗口名字",        #设置窗口的标题
        themename="litera",     #设置主题
        size=(1066,600),        #窗口的大小
        position=(100,100),     #窗口所在的位置
        minsize=(0,0),          #窗口的最小宽高
        maxsize=(1920,1080),    #窗口的最大宽高
        resizable=None,         #设置窗口是否可以更改大小
        alpha=1.0,              #设置窗口的透明度(0.0完全透明)
        )
# root.place_window_center()    #让显现出的窗口居中
# root.resizable(False,False)   #让窗口不可更改大小
# root.wm_attributes('-topmost', 1)#让窗口位置其它窗口之上
root.mainloop()
Nach dem Login kopieren

Label-Stil

So verwenden Sie Python ttkbootstrap

import ttkbootstrap as ttk
from ttkbootstrap.constants import *
root = ttk.Window()
ttk.Label(root,text="标签1",bootstyle=INFO).pack(side=ttk.LEFT, padx=5, pady=10)
ttk.Label(root,text="标签2",boot).pack(side=ttk.LEFT, padx=5, pady=10)
ttk.Label(root,text="标签3",boot).pack(side=ttk.LEFT, padx=5, pady=10)
ttk.Label(root, text="标签4", bootstyle=WARNING, font=("微软雅黑", 15), background='#94a2a4').pack(side=LEFT, padx=5, pady=10)
root.mainloop()
'''
# bootstyle colors
PRIMARY = 'primary'
SECONDARY = 'secondary'
SUCCESS = 'success'
DANGER = 'danger'
WARNING = 'warning'
INFO = 'info'
LIGHT = 'light'
DARK = 'dark'

# bootstyle types
OUTLINE = 'outline'
LINK = 'link'
TOGGLE = 'toggle'
INVERSE = 'inverse'
STRIPED = 'striped'
TOOLBUTTON = 'toolbutton'
ROUND = 'round'
SQUARE = 'square'
'''
Nach dem Login kopieren

Button-Stil

So verwenden Sie Python ttkbootstrap

import ttkbootstrap as ttk
from ttkbootstrap.constants import *
root = ttk.Window()
ttk.Button(root, text="Button 1", bootstyle=SUCCESS).pack(side=LEFT, padx=5, pady=10)
ttk.Button(root, text="Button 2", bootstyle=(INFO, OUTLINE)).pack(side=LEFT, padx=5, pady=10)
ttk.Button(root, text="Button 3", bootstyle=(PRIMARY, "outline-toolbutton")).pack(side=LEFT, padx=5, pady=10)
ttk.Button(root, text="Button 4", boot).pack(side=LEFT, padx=5, pady=10)
ttk.Button(root, text="Button 5", boot).pack(side=LEFT, padx=5, pady=10)
ttk.Button(root, text="Button 6", state="disabled").pack(side=LEFT, padx=5, pady=10) #在禁用状态下创建按钮
root.mainloop()
Nach dem Login kopieren

Button-Klick

So verwenden Sie Python ttkbootstrap

import ttkbootstrap as ttk
from ttkbootstrap.constants import *
root = ttk.Window()
#为按钮添加点击事件
#法一
def button1():
    print("Button1点击了一下!")
ttk.Button(root,text="Button1", bootstyle=(PRIMARY, "outline-toolbutton"),command=button1).pack(side=LEFT, padx=5, pady=10)
#法二
def button2(event): #这里要加一个参数,不然会报错
    print("Button2点击了一下!")
    button_text = event.widget["text"] #得到按钮上的文本
    print(button_text)
b = ttk.Button(root,text="Button2", bootstyle=(PRIMARY, "outline-toolbutton"))
b.pack(side=LEFT, padx=5, pady=10)
b.bind("<Button-1>", button2) #<Button-1>鼠标左键
root.mainloop()
Nach dem Login kopieren

Eingabestil

So verwenden Sie Python ttkbootstrap

import ttkbootstrap as ttk
from ttkbootstrap.constants import *
root = ttk.Window()
e1 = ttk.Entry(root,show=None)
e1.insert(&#39;0&#39;,"默认插入内容")
e1.grid(row=5, column=1, sticky=ttk.W, padx=10,pady=10)
e2 = ttk.Entry(root,show="*",width=50,bootstyle=PRIMARY)
e2.grid(row=10, column=1, sticky=ttk.W, padx=10, pady=10)
e3_content = ttk.StringVar()
e3 = ttk.Entry(root,bootstyle=&#39;success&#39;, textvariable=e3_content).grid(row=15, column=1, sticky=ttk.W, padx=10, pady=10)
def get_entry_contetn():
    print("e1: ",e1.get())
    print("e2: ",e2.get())
    print("e3: ",e3_content.get())
ttk.Button(root,text="get_entry_contetn", bootstyle=(PRIMARY, "outline-toolbutton"),command=get_entry_contetn).grid(row=20, column=1, sticky=ttk.W, padx=10, pady=10)
root.mainloop()
Nach dem Login kopieren

Textfeld (Text)-Stil

So verwenden Sie Python ttkbootstrap

import ttkbootstrap as ttk
from ttkbootstrap.constants import *
root = ttk.Window()
text = ttk.Text(root,)
text.pack(padx=10,pady=10,fill=BOTH)
text.insert(&#39;insert&#39;,&#39;text-content 1&#39;) #插入内容
text.delete("0.0",&#39;end&#39;) #删除内容
text.insert(&#39;insert&#39;,&#39;text-content 2\npy&#39;)
text.see(ttk.END) #光标跟随着插入的内容移动
root.mainloop()
Nach dem Login kopieren

Der Rest ist werden in tkinter nicht häufig verwendet oder sind im offiziellen Tutorial zu tkinter.ttk enthalten.

Das obige ist der detaillierte Inhalt vonSo verwenden Sie Python ttkbootstrap. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
2 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Repo: Wie man Teamkollegen wiederbelebt
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Abenteuer: Wie man riesige Samen bekommt
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Was sind die Vor- und Nachteile des Templatings? Was sind die Vor- und Nachteile des Templatings? May 08, 2024 pm 03:51 PM

Was sind die Vor- und Nachteile des Templatings?

Google AI kündigt Gemini 1.5 Pro und Gemma 2 für Entwickler an Google AI kündigt Gemini 1.5 Pro und Gemma 2 für Entwickler an Jul 01, 2024 am 07:22 AM

Google AI kündigt Gemini 1.5 Pro und Gemma 2 für Entwickler an

So laden Sie Deepseek Xiaomi herunter So laden Sie Deepseek Xiaomi herunter Feb 19, 2025 pm 05:27 PM

So laden Sie Deepseek Xiaomi herunter

Teilen Sie mehrere .NET-Open-Source-KI- und LLM-bezogene Projekt-Frameworks Teilen Sie mehrere .NET-Open-Source-KI- und LLM-bezogene Projekt-Frameworks May 06, 2024 pm 04:43 PM

Teilen Sie mehrere .NET-Open-Source-KI- und LLM-bezogene Projekt-Frameworks

Wie fragst du ihn Deepseek? Wie fragst du ihn Deepseek? Feb 19, 2025 pm 04:42 PM

Wie fragst du ihn Deepseek?

So speichern Sie die Evaluierungsfunktion So speichern Sie die Evaluierungsfunktion May 07, 2024 am 01:09 AM

So speichern Sie die Evaluierungsfunktion

Welche Software ist NET40? Welche Software ist NET40? May 10, 2024 am 01:12 AM

Welche Software ist NET40?

So suchen Sie Deepseek So suchen Sie Deepseek Feb 19, 2025 pm 05:18 PM

So suchen Sie Deepseek

See all articles