Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pyqt5提醒和记事本启动器_Python_User Interface_Pyqt5 - Fatal编程技术网

Python pyqt5提醒和记事本启动器

Python pyqt5提醒和记事本启动器,python,user-interface,pyqt5,Python,User Interface,Pyqt5,我在Python上遇到了一个问题。我试图创建一个提醒和记事本。提醒没有问题,但记事本很难。我使用QPlainTextEdit打开.txt文件、保存注释等。问题是它不起作用。您可以从类fileeki开始查看,因为记事本从那里开始。我的界面是用QTdesigner编写的,文件的类型是ui。我使用的主窗口是convertod to.py from.ui,但其他小部件与.ui中的一样。请帮助我 import sys from PyQt5 import QtCore, QtGui, QtWidgets

我在Python上遇到了一个问题。我试图创建一个提醒和记事本。提醒没有问题,但记事本很难。我使用QPlainTextEdit打开.txt文件、保存注释等。问题是它不起作用。您可以从类fileeki开始查看,因为记事本从那里开始。我的界面是用QTdesigner编写的,文件的类型是ui。我使用的主窗口是convertod to.py from.ui,但其他小部件与.ui中的一样。请帮助我

import sys

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QRadioButton, QVBoxLayout, QStatusBar
from PyQt5.QtWidgets import QLabel, QPushButton, QMessageBox, QFileDialog, QPlainTextEdit
from PyQt5.QtGui import QPixmap
from ui_filebir import Ui_MainWindow
from win10toast import ToastNotifier
import time
import sqlite3
import easygui 
from tkinter import filedialog
from tkinter import *


class MyWidget(QMainWindow,Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.resize(520, 300)

        self.pushButton.clicked.connect(self.notepad_run)
        self.re_but.clicked.connect(self.reminder_run)
        self.pushButton_2.clicked.connect(self.dbrun)
        self.rate = self.lineEdit.text()


    def dbrun(self):
        pass
        #con = sql.connect('dbrate.db')
        #cur = con.cursor()
        #cur.execute(query)
        #res = cur.execute(query)
        #con.commit()
        #con.close()


    def notepad_run(self):
        self.uineweki = fileeki()
        self.uineweki.show()
        self.close()

    def reminder_run(self):
        self.ui_fileush = fileush()
        self.ui_fileush.show()
        self.close()


class fileeki(QWidget):
    def __init__(self, *args, **kwargs):
        super().__init__()
        uic.loadUi('uineweki.ui', self)

        self.editor = QPlainTextEdit()

        self.path = None

        self.pushButton.clicked.connect(self.opening_run)
        self.pushButton_2.clicked.connect(self.saving_run)
        self.pushButton_3.clicked.connect(self.saveac)
        self.pushButton_4.clicked.connect(self.bak)

    def dialog_critical(self, s):
        dlg = QMessageBox(self)
        dlg.setText(s)
        dlg.setIcon(QMessageBox.Critical)
        dlg.show()

    def opening_run(self):
        path, _ = QFileDialog.getOpenFileName(self, "Open file", "", "Text documents (*.txt);All files (*.*)")

        if path:
            try:
                with open(path, 'rU') as f:
                    text = f.read()

            except Exception as e:
                self.dialog_critical(str(e))

            else:
                self.path = path
                self.editor.setPlainText(text)

    def saving_run(self):
        if self.path is None:

            return self.saveac()

        self._save_to_path(self.path)

    def saveac(self):
        path = QFileDialog.getSaveFileName(self, "Save file", "", "Text documents (*.txt);All files (*.*)")

        if not path:

            return

        self._save_to_path(self.path)

    def _save_to_path(self, path):
        text = self.editor.toPlainText()
        try:
            with open(path, 'w') as f:
                f.write(text)

        except Exception as e:
            self.dialog_critical(str(e))

        else:
            self.path = path
            self.update_title()

    def new_run(self):
        pass

    def bak(self):
        self.close()
        self.nazad = MyWidget()
        self.nazad.show()


class fileush(QWidget):
    def __init__(self, *args):
        super().__init__()

        uic.loadUi('ui_fileush.ui', self)
        self.pushButton.clicked.connect(self.running)
        self.pushButton_2.clicked.connect(self.bakk)

    def running(self):
        toaster = ToastNotifier()

        self.first_input = self.lineEdit.text()
        self.second_input = self.lineEdit_2.text()

        t = time.sleep(int(self.first_input))
        toaster.show_toast(self.second_input)


    def bakk(self):
        self.close()
        self.nazad = MyWidget()
        self.nazad.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = MyWidget()
    ex.show()
    sys.exit(app.exec())

my github您正在尝试将文本设置为您创建的新QPlainTextEdit,但实际上应该将其指向gui中使用的文本:

def opening_run(self):
    # ...
        else:
            self.path = path
            # change this
            # self.editor.setPlainText(text)
            # to this
            self.plainTextEdit.setPlainText(text)

这是您在designer中创建的对象(对象名称列在对象检查器树中)。显然,这也意味着你不需要首先创建
self.editor

哇,谢谢你的回答,但是我对这个程序还有一个问题。当我想打开文件时,它会显示一个窗口,其中有文本“预期的字符串或字节,如对象不是元组”,如果保存“预期的字符串或字节,如对象不是非类型”,我测试了您的代码,没有任何问题,检查您是否更改了正在使用的静态QFileDialog方法的参数。对不起,您是通过GitHub打开我的项目的吗?是的,我使用了从大师那里下载的zip。如果你遇到不同的问题,最好创建一个新问题。借此机会编辑您的示例,使其更像一个示例,这可能有助于您同时了解问题的根源。