Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set label width in pixel in tkinter, python [closed]

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


1 Answers

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()
like image 84
acw1668 Avatar answered Oct 23 '25 03:10

acw1668



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!