TKINTER等待多个按钮按下

发布于 2025-02-02 21:42:58 字数 574 浏览 3 评论 0原文

已经创建了一个带有y^x的计算器,它使用wait命令来等待x值被按下。等待只等待一个按钮按下。希望它至少等待5个按钮按下,例如-25.3。如何做?

# Create a wait function that will wait for another key press
def wait_variable(self):
    self.tk.call('tkwait', 'variable', self.equation)

def power(self):
    a = self.get_expression()
    self.equation.set(f"{a} ^ b (enter b)")
    # Call the wait function
    self.wait_variable()
    b = self.get_expression()[-1]
    power_expression = f"math.pow(float({a}), float({b}))"
    _expression = self.get_expression()
    self._calculate_expression(power_expression)

Have created a calculator with, among others, y^x and it uses wait command to wait for x value to be pressed. Wait only waits for one button press. Would like it to wait for at least 5 button presses, such as -25.3. How to do this?

# Create a wait function that will wait for another key press
def wait_variable(self):
    self.tk.call('tkwait', 'variable', self.equation)

def power(self):
    a = self.get_expression()
    self.equation.set(f"{a} ^ b (enter b)")
    # Call the wait function
    self.wait_variable()
    b = self.get_expression()[-1]
    power_expression = f"math.pow(float({a}), float({b}))"
    _expression = self.get_expression()
    self._calculate_expression(power_expression)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帝王念 2025-02-09 21:42:58

我想建议您创建一个全局变量并在每个按钮按下将其递增,然后创建一个用每种按下来调用的函数,并检查变量的值,如果var的值为5,执行件,我希望有帮助。

I would like to suggest that you create a global variable and increment it with every button press, then create a function that gets called with every press and checks the value of the variable, if the var had the value of 5, execute stuff, I hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文