Python 3 – Tkinter Relief styles
Tkinter is a popular Python module used for creating graphical user interfaces. Relief styles is one of the important features in Tkinter to add emphasis or highlight to the widgets. Relief is the edge effect that defines the boundaries of a widget.
Types of Relief styles
Tkinter provides several relief styles that can be applied to widgets. Below are the common types of relief styles in Tkinter:
Flat
Flat is the default relief style for most of the Tkinter widgets. It is a simple flat design with no edge effect or depth.
from tkinter import *
root = Tk()
root.geometry("300x250")
label = Label(root, text="Flat Relief Style", relief="flat")
label.pack(pady=10)
root.mainloop()
Raised
Raised is a relief style that makes the widget appear like it is popping out of the screen. It is commonly used when you want to add depth or a 3D effect to your widget.
from tkinter import *
root = Tk()
root.geometry("300x250")
label = Label(root, text="Raised Relief Style", relief="raised")
label.pack(pady=10)
root.mainloop()
Sunken
Sunken is the opposite of the raised relief style. It makes the widget appear like it is sinking into the screen. It is mostly used to add depth to the widgets and make them look like they are settled into the interface.
from tkinter import *
root = Tk()
root.geometry("300x250")
label = Label(root, text="Sunken Relief Style", relief="sunken")
label.pack(pady=10)
root.mainloop()
Groove
Groove is a relief style that makes the widget appear like it has a groove pushed into it. You can contrast colors to add a better visual effect to this style.
from tkinter import *
root = Tk()
root.geometry("300x250")
label = Label(root, text="Groove Relief Style", relief="groove")
label.pack(pady=10)
root.mainloop()
Ridge
Ridge is the opposite of the groove relief style. It makes the widget appear as if it has a ridge pushed into it. Similarly to groove, contrasting colors can help achieve better results.
from tkinter import *
root = Tk()
root.geometry("300x250")
label = Label(root, text="Ridge Relief Style", relief="ridge")
label.pack(pady=10)
root.mainloop()
Solid
Solid is another simple relief style in Tkinter. As the name suggests, solid makes the widget’s borders look solid without any depth or shadow effects like other relief styles.
from tkinter import *
root = Tk()
root.geometry("300x250")
label = Label(root, text="Solid Relief Style", relief="solid")
label.pack(pady=10)
root.mainloop()
Conclusion
Tkinter relief styles can be very useful in improving the look and feel of your GUI application. You can choose the perfect relief style for a specific widget to achieve a better visual effect. So, start using Tkinter relief styles in your Python projects and make your GUI application more attractive!