简体   繁体   中英

How could I display IntVar with tkinter using place()?

When I use the below code which display using.pack(), the number appeared. However when i change to place, there is no number appeared on the screen. How could I use place to display number instead of pack because I want to set it to specific location?

Code with pack():

import tkinter as tk
 
master_window = tk.Tk()
master_window.geometry("250x150")
master_window.title("IntVar Example")
 
integer_variable = tk.IntVar(master_window, 255)
 
label = tk.Label(master_window, textvariable=integer_variable, height=250)
label.pack()
 
master_window.mainloop()

Code with place ():

import tkinter as tk
 
master_window = tk.Tk()
master_window.geometry("250x150")
master_window.title("IntVar Example")
 
integer_variable = tk.IntVar(master_window, 255)
 
label = tk.Label(master_window, textvariable=integer_variable, height=250)
label.place( x = 80 , y=80 )
 
master_window.mainloop()

How could I set the integer variable using place because i want it to display in specific location?

You've set the label to be 250 characters tall. By default the text appears in the centered in the middle of the label. Because of the size it forces the value off screen. If you are able to make the window tall enough, you'll see the number.

If you remove the height attribute from the label it will show up.

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