python - PyQt: Modifying Widget Object from another Function -


i making multi-page application in pyqt4, whenever user specific action (clicking button example) there update in widgets.


for example, there 5 widgets , 1 button:

3 widgets hidden, 2 widgets shown.

whenever click button, hide 2 widgets, , show 3.

so in code, should this:

# startup     def somefunc(self):         widget1 = qtgui.qlabel("widget1", self)         widget2 = qtgui.qlabel("widget2", self)         widget3 = qtgui.qlabel("widget3", self)         widget4 = qtgui.qlabel("widget4", self)         widget5 = qtgui.qlabel("widget5", self)         widget1.sethidden()         widget2.sethidden()         widget3.sethidden()         widget4.show()         widget5.show()         btn = qtgui.qpushbutton("click", self)         btn.clicked.connect(self.someotherfunc)   # question: (code down below doesn't work, it's example)  def someotherfunc(self):         self.somefunc.widget1.show()         self.somefunc.widget1.show()         self.somefunc.widget1.show()         self.somefunc.widget4.sethidden()         self.somefunc.widget5.sethidden() 

full code:

import sys pyqt4 import qtgui, qtcore import resources  class window(qtgui.qmainwindow):      def __init__(self):         super(window, self).__init__()         self.setgeometry(0, 0, 1280, 800)         self.setwindowtitle("e.s quiz")         self.home()       def home(self):         pic = qtgui.qlabel(self)         pic.setgeometry(0, 0, 1280, 800)         pic.setpixmap(qtgui.qpixmap(":/images/background.png"))         btn = qtgui.qpushbutton("", self)         btn.resize(150, 120)         btn.move(600, 400)         btn.setcursor(qtgui.qcursor(qtcore.qt.pointinghandcursor))         btn.setobjectname('btn')         btn.setstylesheet("#btn {background-image: url(':/images/button1.png'); border: none; }"         "#btn:hover { background-image: url(':/images/button1hover.png'); }"         "#btn:pressed { background-image: url(':/images/button1press.png'); }")         btn.clicked.connect(self.test)         self.show()      def test(self):         print "here"     def startup():     app = qtgui.qapplication(sys.argv)     gui = window()     sys.exit(app.exec_())  startup() 

question:

how modify functions widgets function?

you need store references subwidgets on main window using self

def func(self):     self.btn = qpushbutton(...)     ...  def other_func(self):     self.btn.settext('hello') 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -