I'm working with PYQt5 and Python. Whenever I open a new window and that window has a lineEdit, I have to clic in the lineEdit in order to write any text. Is there a way in which I can start writing the text in the lineEdit just the moment I open the window without, first, having to clic on it?
Thanks!
Edit. Here is the code I've been using
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QVBoxLayout, QMainWindow
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtCore import QTimer, QThread, pyqtSignal, pyqtSlot
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.uic import loadUi
class VentanaInicio(QMainWindow):
path = "null"
def __init__(self):
super(VentanaInicio,self).__init__()
loadUi('D:\Matt\Combi\Archivo.ui',self)
self.pushButton.clicked.connect(self.conectar)
# Abrir Ventana Video
def conectar(self):
self.crear_carpeta()
iniciar = VentanaVideo()
iniciar.exec_()
# Salir
def conectar1(self):
self.close()
def crear_carpeta(self):
VentanaInicio.path = str(self.lineEdit.text())
if not self.lineEdit.text():
VentanaInicio.path = "null"
try:
os.mkdir(VentanaInicio.path)
print("Carpeta Creada")
except FileExistsError:
print("Carpeta Existe")
return VentanaInicio.path
CodePudding user response:
Thanks to musicamante the question was solved. I added the setFocus() like this.
def __init__(self):
super(VentanaInicio,self).__init__()
loadUi('D:\Matt\Combi\Archivo.ui',self)
self.lineEdit.setFocus(True)
self.pushButton.clicked.connect(self.conectar)