PyQt help question

Post here if you need help with creating a Graphical User Interface in Python.

PyQt help question

Postby LavaCreeperKing » Mon Sep 19, 2016 11:14 pm

Hey, so I have been doing stuff with PyQt and I have a question about how you can have a loop running with the program. So I have tried it and yes I can have a loop in my program but the problem is that if I have a GUI window that has a text edit widget and I have a While loop running the window and program work fine but when I try to type something into the text edit widget the text is in all caps. My caps lock is not enabled and if I disable the loop the text will be normal. Now I do understand that I could just convert the text to lowercase but lets say you need a letter to be uppercase. Why is this happening and how can I get around this? Does PyQt offer some kind of built in loop function or something that I need to use instead of a while loop?
LavaCreeperKing
 
Posts: 103
Joined: Wed Sep 02, 2015 11:31 pm

Re: PyQt help question

Postby nilamo » Tue Sep 20, 2016 7:01 pm

There's no reason a while loop would cause your text to be all caps. If anything, it'd cause your app to be unresponsive since you're keeping the main thread busy.
We'll need to see some code to see what's up, because uppercase is not the default for the editor.
This forum is shutting down. Future discussion should take place at http://python-forum.io
User avatar
nilamo
 
Posts: 87
Joined: Thu Jul 21, 2016 8:00 pm
Location: Michigan

Re: PyQt help question

Postby LavaCreeperKing » Wed Sep 21, 2016 6:21 pm

This should work as an example of working code. What you do is enter a size for the pygame window then click the view button it brings up the pygame window when starts the while loop so you can close the pygame window when you click the x button.(This code is part of a program I am making.)After the loop starts if you type a letter into a text edit widget it will be uppercase but if you type in a letter before the loop is tarted or if you stop the loop the letter is in lowercase.

Code: Select all
from PyQt4 import QtCore, QtGui
import sys
import pygame

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s
try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Setup1(object):
    def setupUi(self, Form):
        self.next = False
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(281, 258)
        Form.setAutoFillBackground(False)
        self.View = QtGui.QPushButton(Form)
        self.View.setGeometry(QtCore.QRect(10, 230, 75, 23))
        self.View.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        self.View.setAutoDefault(False)
        self.View.setDefault(False)
        self.View.setFlat(False)
        self.View.setObjectName(_fromUtf8("View"))
        self.Winput = QtGui.QLineEdit(Form)
        self.Winput.setGeometry(QtCore.QRect(10, 140, 71, 20))
        self.Winput.setObjectName(_fromUtf8("Winput"))
        self.Hinput = QtGui.QLineEdit(Form)
        self.Hinput.setGeometry(QtCore.QRect(10, 190, 71, 20))
        self.Hinput.setObjectName(_fromUtf8("Hinput"))

        self.retranslateUi(Form)
        QtCore.QObject.connect(self.View, QtCore.SIGNAL(_fromUtf8("clicked()")), self.pgview)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def pgview(self):
        try:
            self.v = self.Winput.text()
            self.w = int(self.v)
            self.v = self.Hinput.text()
            self.h = int(self.v)
            pygame.display.set_mode([self.w,self.h])
            self.pgloop()
        except ValueError:
            print('Pleas enter a size for the pygame window.')
    def pgloop(self):
        while not self.next:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Pygame Edit Mode", None))
        self.View.setText(_translate("Form", "View", None))

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    Form = QtGui.QWidget()
    ui = Setup1()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())
LavaCreeperKing
 
Posts: 103
Joined: Wed Sep 02, 2015 11:31 pm


Return to GUI

Who is online

Users browsing this forum: No registered users and 6 guests