Tkinter frame expand仅显示“我的窗口”的一半

2024-10-02 02:27:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在tkinter中创建一部手机,我使用了相框,但图像被切成了两半。有人知道为什么吗? 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()

Tags: imagemaintkinterphonerootwidthframetk
1条回答
网友
1楼 · 发布于 2024-10-02 02:27:03

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

  • 更改框架的尺寸

  • 将图片添加到root,如下所示:

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

相关问题 更多 >

    热门问题