我的代码的打印输出是
master.winfo_width:300,winfo_height:300
frame.winfo_width:300,winfo_height:269
为什么frame.winfo_height()
是269而不是300?
环境:Windows 10 Home 64位版本,python 3.7.4,tkinter verion 8.4
import tkinter as tk
from PIL import Image,ImageTk
class MyFrame(tk.Frame,object):
def __init__(self,master=None,width=10,height=10):
super(MyFrame,self).__init__(master)
self.bind_all('<Key>',self.keyevt)
def keyevt(self,evt):
print("self.winfo_width:%d,winfo_height:%d"%(self.winfo_width(),self.winfo_height()))
master = tk.Tk()
master.resizable(False,False)
master.geometry("300x300")
lander = ImageTk.PhotoImage(file="./csdn.png")
frame = MyFrame(master,width=300,height=300)
master.update()
canvas = tk.Canvas(frame)
canvas.pack()
frame.pack()
frame.update()
imagelander = canvas.create_image(150,150,image=lander)
canvas.pack()
print("master.winfo_width:%d,winfo_height:%d"%(master.winfo_width(),master.winfo_height()))
print("frame.winfo_width:%d,winfo_height:%d"%(frame.winfo_width(),frame.winfo_height()))
master.mainloop()