2个按钮重叠的Python Tkinter

2个按钮重叠的Python Tkinter,python,python-3.x,user-interface,button,tkinter,Python,Python 3.x,User Interface,Button,Tkinter,由于反对票的原因,这一点已更新为更清楚的内容 我正在Tkinter中创建一个窗口。此窗口包括: |---------------------------------------------------------------------| | Element | Size | Location | Function Called | |----------|--------------------|-------------------|----

由于反对票的原因,这一点已更新为更清楚的内容


我正在Tkinter中创建一个窗口。此窗口包括:

|---------------------------------------------------------------------|
| Element  | Size               | Location          | Function Called |
|----------|--------------------|-------------------|-----------------|
| mButton1 | Width * Height     | 0, 0              | goDown()        |
| mButton2 | Width/8 * Height/8 | Width/8, Height/8 | goUp()          |
|---------------------------------------------------------------------|
mButton1
按预期工作,单击时调用我的函数
goDown()

mButton2
无法按预期工作,单击时会调用“执行任何操作”

调试后,似乎有“层”,并且
mButton1
位于覆盖
mButton2
的顶层,因此无法按下

我的问题是如何确保
mButton2
位于
mButton1
之上,以便在单击时调用该函数


代码:

import tkinter, sys

root = Tk()
root.geometry("480x320") #Raspberry Pi touchscreen resolution
counter = 30

def goUp():
    counter += 1
    mButton2.config(text = "", borderwidth = 0, highlightthickness=0, relief='ridge', pady = "100")

def downClick():
    counter -= 1
    mButton1.config(text = counter, borderwidth = 0, highlightthickness=0, relief='ridge', pady = "100")

mButton1 = Button(text = counter, command = downClick, height = 4000, width = 320, font = ("Monospace", 200))
mButton1.pack()

mButton2 = Button(text = "", command = downClick, height = 50, width = 50, font = ("Monospace", 10))
mButton2.pack()

root.mainloop()

为了使两个按钮同时工作,您可以从较小的大小和字体开始

如果您想获得更多有关按钮显示位置的命令,请查看其他几何图形管理器Pack在某种程度上受自然因素的限制,在您的情况下似乎还不够

对于要重叠的按钮,可以使用放置管理器:

def upClick():
    global counter
    counter += 1
    mButton1.config(text = counter, borderwidth = 0, highlightthickness=0, relief='ridge', pady = "100")


def downClick():
    global counter
    counter -= 1
    mButton1.config(text = counter, borderwidth = 0, highlightthickness=0, relief='ridge', pady = "100")

mButton1 = Button(text = counter, command = downClick, height = 4000, width = 320, font = ("Monospace", 200))
mButton1.pack()

mButton2 = Button(text = "", command = upClick, height = 5, width = 5, font = ("Monospace", 10))
mButton2.place(anchor="nw")

在问这样一个基本的问题之前,你需要花一点精力学习tkinter。大多数tkinter教程可能会介绍如何做您想做的事情。@BryanOakley我确实尝试过,但无法同时使用两个按钮。然后展示您尝试过的内容。@BryanOakley我刚刚重写了问题。我希望它更好!如果你认为它是,你想,请你投票!谢谢我已经弄明白了,但我想做得更好,以防别人需要帮助!是的,
.place(anchor=“nw”)
在第二个按钮上应该可以工作(但是看起来你还是需要把它变小)非常感谢!我不得不将mButton1.config(text=counter,borderwidth=0,highlightthickness=0)添加到upClick中,但它可以工作!更新,使事情更清楚,为未来的读者。很高兴它成功了:)我刚刚重写了这个问题。我希望它更好!如果你认为它是,你想,请你投票!谢谢我已经弄明白了,但我想做得更好,以防别人需要帮助!