打开窗口时编辑文本

发布于 2025-02-01 03:51:59 字数 1254 浏览 1 评论 0原文

我正在与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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方的韩爷 2025-02-08 03:51:59

多亏了MusicAmante,问题得到了解决。我添加了SetFocus()。

    def __init__(self):
        super(VentanaInicio,self).__init__()
        loadUi('D:\Matt\Combi\Archivo.ui',self)
        self.lineEdit.setFocus(True)

        self.pushButton.clicked.connect(self.conectar)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文