Set label width in pixel in tkinter, python

Viewed 1283

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()
Related