Home > other >  Ask: do a window click on the button, the window title change once, this code has a problem, the nov
Ask: do a window click on the button, the window title change once, this code has a problem, the nov

Time:09-16

 the from PyQt5. Qt import * 
The import sys
Class Window (QWidget) :
Def __init__ (self) :
Super () __init__ ()
Self. Setup_ui ()
Def setup_ui (self) :
Self. TTP ()
Def TTP (self) :
BTN=QPushButton (self)
BTN. SetText (' click ')
BTN. Move (200200)

Def slot_btn (self) :
Print (' 1234 ')
Self. SetWindowTitle (' I changed a ')
BTN. Clicked. Connect (slot_btn)
If __name__=="__main__ ':
App=QApplication (sys. Argv)
Windows window ()=
Window. The show ()
Sys. Exit (app. Exec_ ())

CodePudding user response:

First in terms of your original code, is to write your slot_btn in TTP, want to receive the self must be clicked. Connect (slot_btn) send a self inside, this just python class foundation
 
BTN. Clicked. Connect (lambda: slot_btn (self))


Secondly pyqt5 written not so you have a look at the document again, I also have blog based on designer's introductory tutorial,
  • Related