It's a Python question.

Asked 2 years ago, Updated 2 years ago, 22 views

I am currently learning Python 3.

But I'm posting a question because there's something that doesn't go my way during coding.


class EventedQRadioButton(QtWidgets.QRadioButton):


    def __init__(self, *args, **kwargs):     
        self.memorizeIp=""
        QtWidgets.QRadioButton.__init__(self,*args,**kwargs)

    def mousePressEvent(self, QMouseEvent):
        self.setChecked(not self.isChecked())
        if(self.objectName() == "serverButton"):
            self.memorizeIp = ui.ipEdit.text()

        elif(self.objectName()=="clientButton"):
            ui.ipEdit.setText(self.memorizeIp) 

        return super().mousePressEvent(QMouseEvent)

Create a memoryIp member object in the constructor and then

As the mousePressEvent function is called, conditional statements are performed according to the conditions.

The strange thing about debugging is that when you press serverButton, the value stored in the edit works well

However, if you perform clientButton again and try to get this value and substitute it for edit,

The value has disappeared and is empty.

I don't know the cause of the lack of Python foundation. Please reply. (__)

python

2022-09-22 20:33

3 Answers

        elif(self.objectName()=="clientButton"):
            ui.ipEdit.setText(self.memorizeIp) 

This part

        elif(self.objectName()=="clientButton"):
            print(self.memorizeIp)
            ui.ipEdit.setText(self.memorizeIp) 

When I change to and press clientButton, does the memoryIp value saved in the console window appear? Or only the empty string appears?


2022-09-22 20:33

Empty value appears

I checked it with debugging, but it appeared like that.

There is no code that touches memoryize elsewhere...


2022-09-22 20:33

Sorry for posting the wrong question (__) We solved the problem solved It was a problem outside of the code.


2022-09-22 20:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.