首页 > 解决方案 > 如何修复更改值 def 以便当我按下它的按钮时,我的所有其他按钮都不会被清除?

问题描述

        def change_value():
            global value
            value -= 1
            enteredText = str(Entry.get(spkInpt))
            if value == 0:
                    p1.show
                    displayMain.insert(END, "User:" + enteredText + '\n')
                    displayMain.configure(state='normal')
                    readInput()
                    spkInpt.delete(0, 'end')
                    value = 1
            elif value == 1:
                    p1.show
                    displayMain.configure(state='disabled')  
            else:
                pass
    def speakButton():
        spkBtn=Button(root, text='send', bg='green', font=('Arial',15), command=change_value)
        spkBtn.place(relheight=0.1, relwidth=0.2, relx= 0.2, rely=0.9)
        #check if enter is pressed (not completed !!!!!)
        if keyboard.is_pressed('return'):
            spkBtn()
        else:
            pass
    #Sidebar -------------------------------------------------------------------------------------------------------------------------------------
    def mathButton():
        mathButton=Button(self, text="Math", bg='red', font=("Arial", 15), command=p2.show)
        mathButton.place(relheight=0.1, relwidth=0.2, relx=0, rely=0.1)
    def connectedDevices():
        conDev=Button(self, text="Connected Devices", bg="grey", font=("Arial", 15))
        conDev.place(relheight=0.1, relwidth=0.2, rely=0, relx=0)
    def sidebar():
        mathButton()
        connectedDevices()

我能对 displayMain.insert(END...) 做些什么吗,因为当我按下 speakButton 时,它也会擦除我所有的其他按钮,但是当我只是在没有 change_value 命令的情况下执行按钮时,什么都不会发生,我的按钮保持不变,那又怎样?我是否要阻止我的按钮被擦拭。

标签: pythonpython-3.x

解决方案


推荐阅读