in tkinter when the label have some text the width unit is text unit, my question is simple, how can i set the label width using pixels even if the label contains some text? I'm using the grid method to display the widgets. Thank you for your help
You can assign a zero size image to it, then you can set the width and height of the label in pixels.
Below is a simple example:
import tkinter as tk
root = tk.Tk()
img = tk.PhotoImage() # zero size image
tk.Label(root, text='Hello', image=img, compound=tk.CENTER, width=200, height=100).pack()
root.mainloop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With