Why click on button opens new PyQt window ?
-
Hey guys, i have 3 pyhon files that cooperate and my problem is when i click button that should change text in textbox it also open new window. What is causing it here ? I dont get it
File test.py
from PyQt5 import QtWidgets import sys from PyQt5.QtWidgets import QMainWindow, QApplication, QLineEdit class Window(QMainWindow): def __init__(self): super().__init__() self.textboxvalue2 = "" self.setWindowTitle("Samuel") self.setGeometry(200, 200, 259, 258) self.textbox = QLineEdit(self) self.textbox.move(5, 5) self.textbox.resize(188, 35) self.textbox.setText(str(self.textboxvalue2)) self.textbox.setPlaceholderText("Enter numbers") self.textboxValue = self.textbox.text() self.b10 = QtWidgets.QPushButton(self) self.b10.setText("0") self.b10.move(68, 219) self.b10.resize(60, 35) self.b10.clicked.connect(self.clicked0) self.show() def setExpression(self,expression): self.textbox.setText(str(expression)) def clicked0(self): import Buttons z = Buttons.Button() z.kkt() if __name__ == "__main__": app = QApplication(sys.argv) window = Window() sys.exit(app.exec())
File Buttons.py
from kkts import abstract class Button(abstract): def kkt(self): super().buttonSent("0")
File kkts.py
import test from abc import ABC, abstractmethod x = test.Window() class abstract: @abstractmethod def buttonSent(self,number): global x x.setExpression(number)
-
Hi,
Why are you doing all this convoluted abstract class ?
Just do the update in your clicked0 method.
As for your issue, you are creating two MainWindow. One in your main method and the other in your kkts.py file.
They are both shown because you call show in your class constructor (which is wrong, it's the code that creates the widget that should decide when to show it).
-
Hello @SGaist Thank you for you helpfull reply, i already made changes you mentioned and it is working fine, Thank you a lot!
-
But if i can have one more question, i removed constructor from main.py and i made it normal function and i call this function in if name == "main": And when i do it by this way, textbox again not changing text.... When i have contructor it is working fine, but when i remove construcot and make it function it is not responding
-
But if i can have one more question, i removed constructor from main.py and i made it normal function and i call this function in if name == "main": And when i do it by this way, textbox again not changing text.... When i have contructor it is working fine, but when i remove construcot and make it function it is not responding
@Samuel-Bachorik
Why not show whatever it is you have now so we can see & understand?