猫史档案馆


【Python作品分享】14_GUI_By_Class【求助帖】

用户:郝俊杰2009郝俊杰2009查看:1 回复:4 评论:1 创建时间:2021-10-05T21:12:18


【作品展示】

center_image

 

【作品介绍】

大家帮帮我吧,看看代码哪里有问题

要求Python3.x,安装PySide2库

 

【作品源代码】

import random
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from ui_rannamer import Ui_MainWindow
try:
      with open("roming.txt","r",encoding="utf-8-sig") as f:
            name = f.read()
except:
      pass
class random_name(QMainWindow,Ui_MainWindow):
    while True:
        def __init__(self):
            super().__init__(self)
            self.setupUi(self)
            self.name = ['名字1', '名字2', '名字3', '更多名字']
            self.random_name = []
            self.ipt = ""
            self.num = 0
        def Input(self):
            if self.word:
                self.ipt = self.count.text()
                if self.ipt == "":
                    QMessageBox.warning(self, "注意", "请输入数量")
                else:
                    if self.ipt != "setting":
                            while True:
                                try:
                                        self.num = int(self.ipt)
                                        if self.num > len(self.name):
                                            QMessageBox.warning(self, "哎呦", "数字好像太大了")
                                            raise
                                        if self.num == len(self.name):
                                            QMessageBox.warning(self, "哎呦", "您在点全班?")
                                            raise
                                        random_name = random.sample(self.name, self.num)
                                        QMessageBox.information("恭喜", "{}被抽到了!".format(random_name))
                                        random_name = []
                                        more = 0
                                except:
                                        break
                    if self.ipt == "setting":
                            while True:
                                QMessageBox.information("设置","1.设置名单\n2.Debug信息(一般用处不大)\n3.使用指南\n4.退出 >>>")
                                if self.word:
                                        ipt = self.count.text()
                                        if ipt == "":
                                            QMessageBox.warning(self, "注意", "请输入设置项")
                                        else:
                                            setlist = ipt
                                        if int(setlist) == 1:
                                            self.name = input("请输入新的名单列表(像这样:['名字1','名字2','...'])")
                                        print("改动成功,现列表:", name)
                                        if int(setlist) == 2:
                                            print("--------Debug Info--------")
                                            print("name", self.name)
                                            print("raname pythoncore v13.5")
                                            print("--------Debug Info--------")
                                        if int(setlist) == 3:
                                            print("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------")
                                            print("进阶:\
                                                Q:怎么在不改源代码的情况下更改名库?  A:在程序同目录下创建roming.txt文本文件,然后按照格式写入即可,程序会在每次启动时自动尝试读取(文件格式:['名字1','名字2','......'])\
                                                Q:怎么通过改源代码来更改名库?  A:使用IDLE或者记事本以及其他的文本编辑软件打开源代码,找到第三行的'name = '字样,按照上面写roming.txt的格式更改后面的内容即可,注意要把原来的删掉哦~\
                                                Q:怎么查看此软件的最新版本?  A:前往软件储存库喵NTFS2020/rannamer'即可查看软件最新版本!\
                                                Q:怎么联系软件作者?  A:发邮件喵TA不一定能看到,但是看到了一定会尽他所能回复!\
                                                P.S:有能力的话可以在软件的最新版本页面Fork作者代码,修改/增加代码/功能后向作者请求合并,具体方法参考链接:https://blog.csdn.net/XiaoHanZuoFengZhou/article/details/86518180,文中用到的Git:'https://git-scm.com/downloads',看不懂英文请使用浏览器的翻译功能或者配合手机的翻译软件使用")
                                            print("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------")
                                        if int(setlist) == 4:
                                            break
                                        else:
                                            print("???")
        def keyPressEvent(self, event):
                if event.key() == Qt.Key_Return:
                    self.Input()
if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = random_name()
    sys.exit(app.exec_())

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
郝俊杰2009郝俊杰2009

import random,sys
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from ui_rannamer import Ui_MainWindow
try:
      with open("roming.txt","r",encoding="utf-8") as f:
            name = f.read()
except:
      pass
class random_name(QMainWindow,Ui_MainWindow):
    print("I'm in class")
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        print("func:Setup")
        self.name = ['名字1', '名字2', '名字3', '更多名字']
        self.random_name = []
        self.ipt = ""
        self.num = 0
        self.start = True
        self.Input()
        self.show()
    def Input(self):
        print("func:Input")
        self.ipt = self.count.text()
        if self.ipt == "" and not self.start:
            QMessageBox.warning(self, "注意", "请输入数量")
        else:
            self.start = False
            if self.ipt != "setting":
                while True:
                    try:
                        self.num = int(self.ipt)
                        if self.num > len(self.name):
                            QMessageBox.warning(self, "哎呦", "数字好像太大了")
                            raise
                        if self.num == len(self.name):
                            QMessageBox.warning(self, "哎呦", "您在点全班?")
                            raise
                        if self.num < len(self.name):
                            self.random_name = random.sample(self.name, self.num)
                            print(self.random_name)
                            QMessageBox.information("恭喜", str(self.random_name))
                            random_name = []
                    except:
                        break
            if self.ipt == "setting":
                    while True:
                        QMessageBox.information("设置","1.设置名单\n2.Debug信息(一般用处不大)\n3.使用指南\n4.退出 >>>")
                        if self.word:
                                ipt = self.count.text()
                                if ipt == "":
                                    QMessageBox.warning(self, "注意", "请输入设置项")
                                else:
                                    setlist = ipt
                                if int(setlist) == 1:
                                    self.name = input("请输入新的名单列表(像这样:['名字1','名字2','...'])")
                                    print("改动成功,现列表:", name)
                                if int(setlist) == 2:
                                    print("--------Debug Info--------")
                                    print("name", self.name)
                                    print("raname pythoncore v13.5")
                                    print("--------Debug Info--------")
                                if int(setlist) == 3:
                                    print("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------")
                                    print("进阶:\
                                        Q:怎么在不改源代码的情况下更改名库?  A:在程序同目录下创建roming.txt文本文件,然后按照格式写入即可,程序会在每次启动时自动尝试读取(文件格式:['名字1','名字2','......'])\
                                        Q:怎么通过改源代码来更改名库?  A:使用IDLE或者记事本以及其他的文本编辑软件打开源代码,找到第三行的'name = '字样,按照上面写roming.txt的格式更改后面的内容即可,注意要把原来的删掉哦~\
                                        Q:怎么查看此软件的最新版本?  A:前往软件储存库:'https:/喵NTFS2020/rannamer'即可查看软件最新版本!\
                                        Q:怎么联系软件作者?  A:发邮件到HTTcode2020@126.com,TA不一定能看到,但是看到了一定会尽他所能回复!\
                                        P.S:有能力的话可以在软件的最新版本页面Fork作者代码,修改/增加代码/功能后向作者请求合并,具体方法参考链接:https://blog.csdn.net/XiaoHanZuoFengZhou/article/details/86518180,文中用到的Git:'https://git-scm.com/downloads',看不懂英文请使用浏览器的翻译功能或者配合手机的翻译软件使用")
                                    print("---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------")
                                if int(setlist) == 4:
                                    break
                                else:
                                    print("???")
    def keyPressEvent(self, event):
            if event.key() == Qt.Key_Return:
                self.Input()
if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = random_name()
    sys.exit(app.exec_())

现代码👆

点赞0


评论


fkymfkym

(1):你个是不是没有

window.show()

(2):你ui文件不发出来物怎么看

点赞0


评论


疯疯纸疯疯纸

建议你直接下个Python

点赞0


评论


郝俊杰2009郝俊杰2009

老铁们,我做好了,开源:NTFS2020/rannamer:这是一个由中国的一名科技爱好者编写的随机抽选器。英文名为“ranamer”。//ThisisarandompickerwrittenbyascienceandtechnologyenthusiastinChina.ItsEnglishnameis"ranamer".(github.com)

点赞0


评论