📄 start.py
字号:
# -*- coding: cp936 -*-
from __future__ import division #y要引用这个的 不然是除法会出错的,这个解决了除法自动为0的问题的,这个是向未来的Qt引用的用法
import sys
from PyQt4 import QtCore, QtGui
from random_str import Ui_Form
class StartQt4(QtGui.QMainWindow):
def __init__(self, parent= None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.str_gnr,QtCore.SIGNAL("clicked()"),self.str_generate)
QtCore.QObject.connect(self.ui.cmpr,QtCore.SIGNAL("clicked()"),self.str_compare)
def str_generate(self):
import random
import string
rd = random.randrange(1,40,2)
txt = string.join(random.sample(
[chr(i) for i in range(48,123)],rd)).replace(" ","") #是把字符都串起来,并且将其中的空格都替换没了,就是这样的
self.ui.random_str.setText(txt)
def str_compare(self):
line = self.ui.lineEdit.text()
txt = self.ui.random_str.text()
if len(txt)>= len(line):
leng= len(line)
else:
leng=len(txt)
cnt = 0
for n in range(leng):
if line[n] == txt[n]:
cnt = cnt +1
bi = cnt / len(txt)*100
self.ui.cor_rate.setText("%f%%"%bi)
if __name__== "__main__":
app = QtGui.QApplication(sys.argv)
myapp = StartQt4()
myapp.show()
sys.exit(app.exec_())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -