【问题标题】:When I click on + operator and immediately I want to click on * that's will be change into * but it's not happening当我单击 + 运算符并立即我想单击 * 时,这将变为 * 但它没有发生
【发布时间】:2021-07-07 04:43:47
【问题描述】:

[这是我卡住的图像的截图。如果您想查看我的代码,可以查看我之前的问题,我将所有代码都放在那里。]

https://drive.google.com/file/d/1FUhRz9C-7bge9CWjCYlIFZ_xIfF1XPU9/view?usp=drivesdk

【问题讨论】:

  • 请贴出代码。
  • 这是我之前的问题,你可以查看
  • 问题在哪里
  • 你可以在那里查看我的个人资料,你有我的代码
  • edit您的问题包含minimal reproducible example

标签: python tkinter calculator


【解决方案1】:

首先请通过how to ask questions on StackOverflow

在您提出的每个问题中,您都需要保持专业并通过Minimal, Reproducible Example适当地提问


现在,回答您的问题: 您可以检查最后一个字符的条件,如果它以前是一个运算符,然后删除最后一个字符(最后一个运算符)以使用新运算符更新字符串。 例如

def btnclick(num):
    global start
    if (start[-1]=='+'  or start[-1]=='-' or start[-1]=='*' or start[-1]=='/') and (num=='+' or num=='-' or num=='*' or num=='/'):
        start=start[:-1]    
    start=start+str(num)
    text.set(start)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-28
    • 2014-05-16
    • 2015-02-15
    • 1970-01-01
    • 2022-08-10
    • 1970-01-01
    • 2021-08-13
    • 2016-10-03
    相关资源
    最近更新 更多