打开窗口时编辑文本
我正在与Pyqt5和Python合作。每当我打开一个新窗口并且该窗口都有一个LineDit时,我都必须在LineDit中插入,才能写任何文本。有没有办法在我打开窗口的那一刻,首先不得不在窗口上写上文本?
谢谢!
编辑。这是我一直在使用的代码
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
多亏了MusicAmante,问题得到了解决。我添加了SetFocus()。
Thanks to musicamante the question was solved. I added the setFocus() like this.