【发布时间】:2017-09-11 04:59:50
【问题描述】:
由于投反对票,这已更新为更加清晰
我正在 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()
【问题讨论】:
-
在问这样一个基本问题之前,您需要花一点时间学习 tkinter。大多数 tkinter 教程可能会涵盖如何做你想做的事。
-
@BryanOakley 我确实尝试过,但无法同时使用 2 个按钮。
-
然后显示你的尝试。
-
@BryanOakley 我刚刚重写了这个问题。我希望它会更好!如果你认为它是并且你想要它,你可以请你投票!谢谢!我已经想通了,但想把它做得更好,以防其他人需要帮助!
标签: python python-3.x user-interface button tkinter