我正在尝试查找tk.Toplevel()
窗口的大小,以便将其居中:
class HelpWindow:
def __init__(self, master):
self.width, self.height = screenDim
self.master = master
self.helpImage = Image.open("someImage.jpg")
self.helpPhoto = ImageTk.PhotoImage(self.helpImage)
self.helpLabel = tk.Label(self.master, image = self.helpPhoto)
self.helpLabel.grid(row = 1)
self.masterSize = self.master.geometry().split('+')[0].split('x')
# this is just ['1', '1']; not the actual size
self.xSize, self.ySize = (float(self.width) / float(self.masterSize[0])), (float(self.height) / float(self.masterSize[1]))
# this creates the offset
self.xPos, self.yPos = int(self.width/2 - (self.width/(self.xSize*2))), int(self.height/2 - (self.height/(self.ySize*2))) # this should center it
self.master.geometry("+{posX}+{posY}".format(posX = self.xPos, posY = self.yPos))
我怎样才能得到实际尺寸?self.masterSize = self.master.geometry().split('+')[0].split('x')
is just ['1', '1']
,这不是窗口的大小,因此它不会使窗口居中...