Tkinter frame expand 只显示我的一半 window

Tkinter frame expand is only displaying half my window

我正在尝试在 tkinter 中创建一个 phone,我正在使用框架,但图像被切成两半。有谁知道为什么? https://i.stack.imgur.com/mOtEn.png

import tkinter as tk

def raiseframe(frame):
    frame.tkraise()

root = tk.Tk()

bgImage = tk.PhotoImage(file="Phone.gif")
WALogo = tk.PhotoImage(file="whatsappLogo.gif")
width = bgImage.width()
height = bgImage.height()

root.title("Phone")
root.geometry("%dx%d+0+0" % (width, height))

main = tk.Frame()
whatsapp = tk.Frame()

for frame in (main, whatsapp):
    frame.pack(fill = tk.BOTH, expand = True)

#Mainscreen:
canvas = tk.Canvas(main, width = width, height = height, bg = "black")
canvas.create_image((width / 2, height / 2), image = bgImage)
canvas.place(x = 0, y = 0)
WAB = tk.Button(main, image = WALogo, command = lambda: raiseframe(whatsapp))
WAB.place(x = 35, y = 85)

raiseframe(main)
root.mainloop()

我相信你已经将图片添加到一个只占屏幕一半的框架中。 您可以:

  • 更改框架的尺寸

  • 像这样将图片添加到root:

canvas = tk.Canvas(root, width = width, height = height, bg = "black")
canvas.create_image((width / 2, height / 2), image = bgImage)