gpt4 book ai didi

python - Tkinter 框架扩展只显示我的窗口的一半

转载 作者:行者123 更新时间:2023-12-04 10:37:21 32 4
gpt4 key购买 nike

我正在尝试在 tkinter 中创建手机,并且正在使用框架,但图像被切成两半。有谁知道为什么?
/image/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()

最佳答案

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

  • 更改框架尺寸
  • 像这样将图片添加到根目录:
  • canvas = tk.Canvas(root, width = width, height = height, bg = "black")
    canvas.create_image((width / 2, height / 2), image = bgImage)

    关于python - Tkinter 框架扩展只显示我的窗口的一半,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60101225/

    32 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com