2个按钮重叠Python Tkin

2024-06-28 19:29:06 发布

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

由于投了反对票,这一点已被更新为更加清晰


我正在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未按预期工作,单击时确实调用do anything。在

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

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


代码:

^{pr2}$

Tags: 函数sizetkinterfunctionlocationelementwidthdo
1条回答
网友
1楼 · 发布于 2024-06-28 19:29:06

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

如果您想对按钮的显示位置有更多的命令,请查看其他几何图形管理器。包装在某种程度上受到了自然的限制,在你的情况下似乎还不够。在

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

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")

相关问题 更多 >