I can't figure out how to put buttons on top off my background picture, I've tried many forums, but none off the answers worked

前端 未结 2 875
一整个雨季
一整个雨季 2021-01-17 03:47

So I am making a \"HUB\" for my game, and I got my background there, but I can\'t display the buttons over the background. I\'ve searched up on many forums and none off the

2条回答
  •  梦毁少年i
    2021-01-17 04:28

    I have adapted your code to work on my side.. just a few tweaks will make what I think you wanted as a result :-)

    You may want to document on columnconfigure and rowconfigure, and the sticky parameter of the grid method.

    from tkinter import *    
    root = Tk()
    root.geometry("1280x640")
    root.title("Choose level")
    
    # Let's assume we are not using your frame.
    #topFrame = Frame(root, width=1280, height=640)
    #topFrame.grid(row=0)
    
    background = PhotoImage(file="HUB_BG.png")
    background1 = Label(root, image=background)
    
    # adding a column to use columnconfigure and rowconfigure...
    # using sticky so the image stays expanded in your widget
    background1.grid(column=0, row=0, sticky='nsew')
    # Below will stick your background label so it doesn't resize with your widgets
    root.columnconfigure(0, weight=1)
    root.rowconfigure(0, weight=1)
    
    # replaced topframe with background1.
    level1 = Button(background1, text="Level 1")
    level1.grid(row=0)
    level2 = Button(background1, text="Work in progress")
    level2.grid(row=1)
    

提交回复
热议问题