python编辑图形界面单一功能MAC随机地址生成
无版权,随便改,单一功能,很好改,可以自己扩展需要随机密码,随机用户名,随机EMAIL名,随机随机~# -*- coding: utf-8 -*-
#@copyright python36
from PyQt5 import QtWidgets,QtCore,QtGui
from sys import argv,exit
from os import system
from datetime import datetime,timedelta
from random import sample
class Ui_MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.retranslateUi(self)
self.codeall=0
self.codeok=0
self.todaystr=''
self.macstr=''
def setupUi(self, MainWindow):
MainWindow.resize(365,265)
MainWindow.setFixedSize(365,265)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.from_dy_btn = QtWidgets.QPushButton(self.centralwidget)
self.from_dy_btn.setGeometry(QtCore.QRect(10, 50, 75, 30))
self.from_dy_text = QtWidgets.QTextEdit(self.centralwidget)
self.from_dy_text.setGeometry(QtCore.QRect(95, 10, 250, 100))
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(10, 200, 150, 30))
self.label_codeall = QtWidgets.QLabel(self.centralwidget)
self.label_codeall.setGeometry(QtCore.QRect(10, 120, 35, 30))
self.label_codeall_child = QtWidgets.QLabel(self.centralwidget)
self.label_codeall_child.setGeometry(QtCore.QRect(47, 120, 130, 30))
self.label_codeok = QtWidgets.QLabel(self.centralwidget)
self.label_codeok.setGeometry(QtCore.QRect(175, 120, 35, 30))
self.label_codeok_child = QtWidgets.QLabel(self.centralwidget)
self.label_codeok_child.setGeometry(QtCore.QRect(212, 120, 130, 30))
# 左边距, 上边距 ,宽,高
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow","随机数"))
self.todaystr=(datetime.now()).strftime("%Y-%m-%d %H:%M:%S")
self.label.setText(_translate("MainWindow",self.todaystr))
self.label_codeall.setText(_translate("MainWindow","请求数"))
self.label_codeall_child.setText(_translate("MainWindow","0"))
self.label_codeok.setText(_translate("MainWindow","处理数"))
self.label_codeok_child.setText(_translate("MainWindow","0"))
self.from_dy_btn.setText(_translate("MainWindow","GO"))
self.from_dy_btn.clicked.connect(self.get_id)
self.from_dy_text.setPlainText(_translate("MainWindow","随机MAC地址"))
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.time_go)
self.timer.start(1000)
def time_go(self):
self.todaystr=(datetime.now()).strftime("%Y-%m-%d %H:%M:%S")
self.label.setText(self.todaystr)
def get_id(self):
self.codeall+=1
self.label_codeall_child.setText(str(self.codeall))
try:
Maclist = []
for i in range(1,7):
RANDSTR = "".join(sample("0123456789ABCDEF",2))
Maclist.append(RANDSTR)
self.macstr="".join(Maclist)
except Exception:
self.from_dy_text.setPlainText('get_id: '+str(Exception))
else:
self.from_dy_text.setPlainText(self.macstr)
self.codeok+=1
self.label_codeok_child.setText(str(self.codeok))
if __name__ =='__main__':
app = QtWidgets.QApplication(argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
exit(app.exec_())
不错,看看。。。。 大哥,有没有py安装包?
页:
[1]