#importing everything
from tkinter import *
from PIL import Image
#making the root window
root = Tk()
dimension = '800x500'
#setting the window
im = Image.open(r'C:\Users\Hunter\Desktop\school 1\module\pbm\bg.png')
bg = PhotoImage(im)
window = Label(root, bd=0, height=70, width=50)
window.image=bg
window.pack(fill=Y, expand=True, side=BOTTOM)
#overriding the default properties
root.overrideredirect(True)
root.geometry(dimension)
#the main title bar
title_bar = Frame(root, bg='#496E82', bd=0, height=4)
#pack all the widgets
title_bar.pack(fill=X, side=TOP)
#code for moving the window
def get_pos(event):
xwin = root.winfo_x()
ywin = root.winfo_y()
startx = event.x_root
starty = event.y_root
ywin = ywin - starty
xwin = xwin - startx
def move_window(event):
root.geometry(dimension + '+{0}+{1}'.format(event.x_root + xwin, event.y_root + ywin))
startx = event.x_root
starty = event.y_root
title_bar.bind('<B1-Motion>', move_window)
#binding the title bar so that it moves
title_bar.bind('<Button-1>', get_pos)
#main thing
root.mainloop()
当我运行上面的代码时,它隐藏了所有东西,它唯一显示的是一个白色窗口,没有别的。它还隐藏了顶部的框架(标题栏)。但是当我为标签设置背景颜色时,它也会隐藏所有内容,框架和所有内容,并显示该颜色的窗口。我想做的事情是向我的应用程序添加背景图片,然后在背景图片的顶部添加其他 tkinter 小部件,如标签、按钮等。帮助将不胜感激!
编辑:
当我从标签中删除height
andwidth
属性时会发生这种情况。如何使图像y-axis
也覆盖,而不仅仅是覆盖x-axis
。它还吃掉了顶部的框架。如何解决这一切?