简体   繁体   中英

Why does “ttk.style()” adds additional styles to the Entry widget?

So, I have 4 Entry Widgets on my window and I just wanted to add some internal left padding on the last Entry Widget. I did so using ttk.style() , which added the desired padding but it also added some additional styling like a black border , some hover effect, then the entry widget gets a blue border when selected.
This is my Code:

from tkinter import *
from tkinter import ttk

root = Tk()
root.configure(padx=50)

input1 = Entry(root)
input1.grid(row=1, column=0, pady=10)
input2 = Entry(root)
input2.grid(row=2, column=0, pady=10)
input3 = Entry(root)
input3.grid(row=3, column=0, pady=10)

style = ttk.Style(root)
style.configure('padded.TEntry', padding=[15, 0, 0, 0])

e = ttk.Entry(root, style='padded.TEntry')
e.grid(row=4,column=0, pady=10)

root.mainloop()

Look how the 4th Entry Widget has a Black Border around it

看看第 4 个条目小部件周围有一个黑色边框

Look how a Blue Border appears when the widget is selected

在此处输入图像描述

The only styling that I was excepting is the little increase in width because of the left-padding, but how are these other styles being triggered.

It is because the fourth entry is a ttk.Entry widget but the other three are tkinter.Entry widgets. If you make all four ttk.Entry widgets you'll see that they all have the additional styles.

Even though the tkinter and ttk modules have widgets with the same name, they are completely different widgets with their own sets of defaults.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM