Python-PYQT5 製作一個登陸介面
工具/版本
(1)安裝環境:Windows7 64bit
(2)使用版本Python3.6
(3)PYQT5
(4)eric6
主要涉及的內容:
(1)tableWidget的使用
(2)QLineEdit的的的的的的的使用
(3)各個位置增加圖示
(4)從登陸屆面跳到主視窗
(5)TCP / IP通訊
(6)訪問資料庫
一,登陸介面
1,介面設定圖示和標題
self.resize(500, 300) # 設定大小 self.setWindowTitle("XX登入介面") # 設定標題 self.setFixedSize(self.width(), self.height()) # 禁止最大化 icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap("..\\Image\\10.jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.setWindowIcon(icon) # 設定視窗的圖示
設定完成後,我們發現電腦工作列的圖示並沒有修改,setWindowIcon這個函式起了一半的作用,學的Qt的的的的的都知道這個函式同時設定了程式的兩個地方的圖示顯示,修改方法看參考如下連結
需要讓窗戶知道
import ctypes
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")
2,按鈕美化
參考這篇文章
self.pushButton_2.setFlat(True) # 設定按鍵邊框取消
效果如下
#!/usr/bin/env python # encoding: utf-8 """ +----------------------------------------------------------------------------+ ╱◥██◣ ∧_∧ ∧_∧ ∧_∧ ∧_∧ ╱◥██◣ |田︱田田| (^ .^) (^ 、^) (^ 0^) (^ Д^) |田︱田田| ╬╬╬╬╬╬╬╬╬╬-------∪-∪-------∪-∪--------∪-∪-------∪-∪---╬╬╬╬╬╬╬╬╬╬╬ +----------------------------------------------------------------------------+ License (C) Copyright 2017-2017, Corporation Limited. File Name : UI_progressBar.py Auther : samenmoer Software Version : Python3.6 Email Address :
[email protected] Creat Time : 2018-10-28 17:27:02 CSDN blog : https://blog.csdn.net/samenmoer Description : ------------------------------------------------------------------------------ Modification History Data By Version Change Description ============================================================================== ${time} | | | ============================================================================== ¤╭⌒╮ ╭⌒╮¤╭⌒╮ ╭⌒╮¤╭⌒╮ ╭⌒╮¤╭⌒╮ ╭⌒╮¤╭⌒╮╭⌒╮¤╭⌒╮╭⌒╮¤╭⌒╮╭⌒╮¤╭⌒╮╭⌒╮¤╭⌒╮╭⌒╮¤╭⌒╮ ------------------------------------------------------------------------------ """ import sys from PyQt5 import QtGui from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QPushButton from PyQt5.QtGui import QPixmap, QIcon, QMovie from PyQt5.QtCore import QThread, pyqtSignal class UI_LoginBar(QWidget): def __init__(self, parent=None): super(UI_LoginBar, self).__init__(parent) self.setupUi() self.pushButton.clicked.connect(self.run) self.pushButton2.clicked.connect(self.run) def setupUi(self): self.setObjectName("MainWindow") self.resize(500, 300) # 設定大小 self.setWindowTitle("XX登入介面") # 設定標題 self.setFixedSize(self.width(), self.height()) # 禁止最大化 icon = QIcon() icon.addPixmap(QPixmap("..\\Image\\10.jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.setWindowIcon(icon) # 設定視窗的圖示 self.pushButton = QPushButton(self) self.pushButton.setGeometry(135, 230, 230, 30) self.pushButton2 = QPushButton(self) self.pushButton2.setGeometry(135, 265, 230, 30) self.pushButton.setObjectName("pushButton") self.pushButton.setText("登入") self.lable = QLabel(self) self.lable.setGeometry(75, 100, 350, 50) self.movie = QMovie("1.gif") def run(self): self.lable.setMovie(self.movie) if self.sender() == self.pushButton: self.movie.start() else: self.movie.stop() self.lable.setPixmap(QPixmap("")) """ class Thread(QThread): _signal = pyqtSignal(bool) def __init__(self, parent=None): super(Thread, self).__init__(parent) self.working = True def __del__(self): self.wait() self.working = False def run(self): # 執行緒相關程式碼 while self.working is True: self._signal.emit(True) self.sleep(0.8) self._signal.emit(False) self.sleep(0.8) class UI_LoginBar(QWidget): def __init__(self, parent=None): super(UI_LoginBar, self).__init__(parent) self.setupUi() #self.Runthread() # 建立一個新的執行緒 self.pushButton.clicked.connect(self.Runthread) self.pushButton2.clicked.connect(lambda: self.thread.terminate()) def Runthread(self): self.thread = Thread() self.thread._signal.connect(self.callback) self.thread.start() def threadstop(self): self.thread.terminate() def setupUi(self): self.setObjectName("MainWindow") self.resize(500, 300) # 設定大小 self.setWindowTitle("XX登入介面") # 設定標題 self.setFixedSize(self.width(), self.height()) # 禁止最大化 icon = QIcon() icon.addPixmap(QPixmap("..\\Image\\10.jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.setWindowIcon(icon) # 設定視窗的圖示 self.pushButton = QPushButton(self) self.pushButton.setGeometry(135, 230, 230, 30) self.pushButton2 = QPushButton(self) self.pushButton2.setGeometry(135, 280, 230, 30) self.pushButton.setObjectName("pushButton") self.pushButton.setText("登入") self.lable = QLabel(self) self.lable.setGeometry(75, 100, 350, 50) self.png = QPixmap("..\\Image\\1.png") self.png2 = QPixmap("..\\Image\\2.png") def callback(self, status): if status is True: self.lable.setPixmap(self.png) elif status is False: self.lable.setPixmap(self.png2) else: self.lable.setPixmap(QPixmap("")) # ========================================================================== # * Founction Name : ModuleInit # * Parameter : None # * Return : None # * Description : 為當前模組設定Log頭,方便識別,以及其他初始化設定 # ========================================================================== """ if __name__ == '__main__': app = QApplication(sys.argv) ui = UI_LoginBar() ui.show() sys.exit(app.exec_())
import re
import sys
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import QMainWindow, QApplication, QLineEdit
from PyQt5.QtCore import Qt, pyqtSlot
from PassWordEdit import PwdLineEdit
import ctypes
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")
class LogIn_UI(QMainWindow):
def __init__(self, parent=None):
super(LogIn_UI, self).__init__(parent)
self.SetupUi()
self.pushButton.clicked.connect(self.test)
def test(self):
self.hide()
def SetupUi(self):
self.setObjectName("MainWindow")
self.resize(500, 300) # 設定大小
self.setWindowTitle("XX登入介面") # 設定標題
self.setFixedSize(self.width(), self.height()) # 禁止最大化
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("..\\Image\\10.jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.setWindowIcon(icon) # 設定視窗的圖示
self.checkBox = QtWidgets.QCheckBox(self)
self.checkBox.setGeometry(QtCore.QRect(130, 180, 91, 16))
self.checkBox.setObjectName("checkBox")
self.checkBox.setText("記住賬號")
self.checkBox_2 = QtWidgets.QCheckBox(self)
self.checkBox_2.setGeometry(QtCore.QRect(280, 180, 91, 16))
self.checkBox_2.setObjectName("checkBox_2")
self.checkBox_2.setText("自動登入")
self.pushButton = QtWidgets.QPushButton(self)
self.pushButton.setGeometry(QtCore.QRect(135, 230, 230, 30))
self.pushButton.setObjectName("pushButton")
self.pushButton.setText("登入")
self.tableWidget = QtWidgets.QTableWidget(self)
self.tableWidget.setGeometry(QtCore.QRect(120, 70, 260, 90))
self.tableWidget.setObjectName("tableWidget")
self.TableSet()
self.pushButton_3 = QtWidgets.QPushButton(self)
self.pushButton_3.setGeometry(QtCore.QRect(400, 75, 72, 30))
self.pushButton_3.setObjectName("pushButton_3")
self.pushButton_3.setText("註冊賬號")
self.pushButton_4 = QtWidgets.QPushButton(self)
self.pushButton_4.setGeometry(QtCore.QRect(400, 120, 72, 30))
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_4.setText("修改密碼")
self.pushButton_2 = QtWidgets.QPushButton(self)
self.pushButton_2.setGeometry(QtCore.QRect(25, 80, 70, 70))
self.pushButton_2.setText("")
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_2.setFlat(True) # 設定按鍵邊框取消
self.pushButton_2.setIconSize(QtCore.QSize(70, 70))
self.pushButton_2.setIcon(QtGui.QIcon("..\\Image\\16.jpg"))
def TableSet(self):
self.table = self.tableWidget
self.table.setColumnCount(1)
self.table.setRowCount(2)
# 設定表頭隱藏顯示
self.table.setVerticalHeaderLabels(['賬號', '密碼'])
self.table.verticalHeader().setVisible(True)
self.table.horizontalHeader().setVisible(False)
# 設定行高列寬
self.table.setColumnWidth(0, 220)
self.table.setRowHeight(0, 44)
self.table.setRowHeight(1, 44)
# 賬號密碼設定
self.PassWordSet()
self.IdentitySet()
self.table.setCellWidget(0, 0, self.IdentityItem)
self.table.setCellWidget(1, 0, self.PassWordItem)
#@pyqtSlot()
def IdentitySet(self):
self.IdentityItem = QLineEdit()
self.IdentityItem.installEventFilter(self)
self.IdentityItem.setClearButtonEnabled(True)
def PassWordSet(self):
self.PassWordItem = PwdLineEdit()
self.PassWordItem.installEventFilter(self)
# self.PassWordItem.setText("hello")
# 禁止右鍵選單
self.PassWordItem.setClearButtonEnabled(True)
self.PassWordItem.setContextMenuPolicy(Qt.NoContextMenu)
self.PassWordItem.setPlaceholderText("密碼>8位 可輸入數字字母字元")
#self.PassWordItem.setEchoMode(QLineEdit.Password)
@pyqtSlot()
def on_PassWordItem_editingFinished(self):
regex_pwd = "^([A-Z]|[a-z]|[0-9]|[`[email protected]#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“'。,、?]){6,16}$"
self.pwd1 = self.lineEdit_2.GetPassword()
if len(self.pwd1) > 0:
self.lineEdit_6.clear()
rrpwd = re.compile(regex_pwd)
if rrpwd.match(self.pwd1) is None:
self.lineEdit_6.setText('密碼不符合要求!')
else:
self.lineEdit_6.setText('密碼未填寫!')
if __name__ == '__main__':
app = QApplication(sys.argv)
ui = LogIn_UI()
ui.show()
sys.exit(app.exec_())
#!/usr/bin/env python
# encoding: utf-8
"""
+----------------------------------------------------------------------------+
╱◥██◣ ∧_∧ ∧_∧ ∧_∧ ∧_∧ ╱◥██◣
|田︱田田| (^ .^) (^ 、^) (^ 0^) (^ Д^) |田︱田田|
╬╬╬╬╬╬╬╬╬╬-------∪-∪-------∪-∪--------∪-∪-------∪-∪---╬╬╬╬╬╬╬╬╬╬╬
+----------------------------------------------------------------------------+
License (C) Copyright 2017-2017, Corporation Limited.
File Name : PassWordEdit.py
Auther : samenmoer
Software Version : Python3.6
Email Address : [email protected]
Creat Time : 2018-10-06 19:34:17
CSDN blog : https://blog.csdn.net/samenmoer
Description :
------------------------------------------------------------------------------
Modification History
Data By Version Change Description
==============================================================================
${time} | | |
==============================================================================
¤╭⌒╮ ╭⌒╮¤╭⌒╮ ╭⌒╮¤╭⌒╮ ╭⌒╮¤╭⌒╮ ╭⌒╮¤╭⌒╮╭⌒╮¤╭⌒╮╭⌒╮¤╭⌒╮╭⌒╮¤╭⌒╮╭⌒╮¤╭⌒╮╭⌒╮¤╭⌒╮
------------------------------------------------------------------------------
"""
from RecordLog import print_log
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtCore import QTimer
# ==========================================================================
# * Founction Name : ModuleInit
# * Parameter : None
# * Return : None
# * Description : 為當前模組設定Log頭,方便識別,以及其他初始化設定
# ==========================================================================
def ModuleInit():
global LogHead
LogHead = "[wait to fill]"
print_log("檔案初始化完成", LogHead=LogHead)
return
class PwdLineEdit(QLineEdit):
def __init__(self):
super().__init__()
self.m_LineEditText = ""
self.m_LastCharCount = 0
self.Action()
def Action(self):
self.cursorPositionChanged[int,int].connect(self.DisplayPasswordAfterEditSlot)
self.textEdited[str].connect(self.GetRealTextSlot)
self.time = QTimer(self)
self.time.setInterval(500)
self.time.start()
self.show()
def DisplayPasswordAfterEditSlot(self, old, new):
print('new:', new)
print('old:', old)
if old >= 0 and new >= 0:
if new > old:
self.time.timeout.connect(self.DisplayPasswordSlot)
else:
self.setCursorPosition(old)
def DisplayPasswordSlot(self):
self.setText(self.GetMaskString())
def GetRealTextSlot(self, text):
self.m_LastCharCount = len(self.m_LineEditText)
if len(text) > self.m_LastCharCount:
self.m_LineEditText += text[-1]
elif len(text) <= self.m_LastCharCount:
self.m_LineEditText = self.m_LineEditText[:-1]
def GetMaskString(self):
mask = ""
count = len(self.text())
if count > 0:
for i in range(count):
mask += "*"
return mask
def GetPassword(self):
return self.m_LineEditText
相關推薦
Python-PYQT5 製作一個登陸介面
工具/版本 (1)安裝環境:Windows7 64bit (2)使用版本Python3.6 (3)PYQT5 (4)eric6 用到的圖片 主要涉及的內容: (1)tableWidget的使用 (2)QLineEdit的的的的的的的使用 (3)各個位置增加圖
java swing 製作一個登陸介面,親測有效
一、介紹 Swing 是一個為Java設計的GUI工具包。 Swing是JAVA基礎類的一部分。 Swing包括了圖形使用者介面(GUI)器件如:文字框,按鈕,分隔窗格和表。 Swing提供許多比AWT更好的螢幕顯示元素。它們用純Java寫成,所以同Java本身一樣可以跨平臺執行,這一點不像AWT。它
製作一個畫圖介面
製作一個畫圖介面主要分為四個步驟 一、 建立一個圖畫介面 利用Java 的 swing,awt 提供的相關內容進行繪畫 二、 處理事件 事件監
qt實現一個登陸介面-------------------qt之mysql增、刪、改、查、基本操作。
https://www.cnblogs.com/baimt/p/5688517.html安裝的MySQL的的步驟可以參考該博主的文章。 專案描述:實現一個登入介面,登入成功後切換到另一個介面。 登入介面實現的功能有: 1. qt連線mysql建立表.2。註冊賬號,往mysql表裡面新增賬
vtk python 如何製作一個骰子
import vtk cube=vtk.vtkCubeSource() cube.SetCenter(0.0,0.0,0.0) cube.SetXLength(10) cube.SetZLength(10) cube.SetYLength(10) cubeMapper = vtk.vtkPol
筆記︱利用python + flask製作一個簡易本地restful API
pip install flask-restful . 一、案例解析 由一個完整案例解析: from flask import Flask from flask.ext.restful import reqparse, abort,
python作業:編寫登陸介面
#!/usr/bin/env python # Robin # 作業二:編寫登陸介面 # 輸入使用者名稱密碼 # 認證成功後顯示歡迎資訊 # 輸錯三次後鎖定 username = "robin" pa
android一個登陸介面的設計
說起登陸介面的設計,大家可能都會說這個挺簡單的的啊,弄個佈局,加幾個控制元件一個登陸介面就出來了,但我今天想說一下自己在設計一個登陸介面時遇到的問題,而我這個登陸介面的設計重點就是在一個水平佈局上放了一個checkbox和一個登陸的button,在checkbox放上之後,
Flask學習之旅--用 Python + Flask 製作一個簡單的驗證碼系統
一、寫在前面 現在無論大大小小的網站,基本上都會使用驗證碼,登入的時候要驗證,下載的時候要驗證,而使用的驗證碼也從那些簡簡單單的字元圖形驗證碼“進化”成了需要進行圖文識別的驗證碼、需要拖動滑塊的滑動驗證碼、甚至還有手機驗證碼。當你與之打交道的時候,有沒有考慮過其背後的原理呢?當然
python之PyQt4製作登陸介面
對於初次做GUI程式的人來說,確實登陸視窗程式會造成困惑,以前做Delphi時也有人問過我,好不容易人家才理解清楚,PyQt也是一樣的。 一般有兩種處理方式: 第一種:在開啟主窗體前開啟登陸對話方塊,如果登陸成功,再建立主窗體並開啟; 第二種:在建立主窗體後,在顯示主窗體前開啟登陸對話方塊,如果登陸成功,
最近開始努力學python 寫了一個python小代碼:判斷一個登陸程序,如果賬號密碼輸錯3次,鎖定賬號無法再登陸
登陸 readlines 輸入 連續 nbsp 努力 一個 取數據 lis 1 count = 0 2 username = ‘zhangsan‘ 3 userpassword = ‘111111‘ 4 5 f = open(‘lock.txt‘,‘r+‘
給Python爬蟲做一個介面.上
<p>做爬蟲做了那麼久,開始逐漸不滿足寫好程式,每次只能完成一件事情。開始思考如何可以做一個簡單介面互動,再增加爬蟲的可操作室,做互動介面有兩個思路:</p> 用Django做一個web介面; 用PyQt做一個exe程式介面; <p>事實上
Python 運用所學知識製作一個歌詞解析器,要求:輸入時間給出對應歌詞
學了將近兩週python了,遇到了一道挺有意思的題分享一下: 製作一個歌詞解析器,要求:輸入一個時間點能給出對應時間的歌詞 廢話不多說,直接上圖,基本每步都有註釋: mulrc = '''[ti:藍蓮花] [ar:許巍] [al:留聲十年絕版青
【python tkinter】登陸介面
密碼輸入錯誤會彈出messagebox,輸入正確後可調轉到MainPage(下一節編寫) from tkinter import * from tkinter.messagebox import * class LoginPage(Frame): def __init__(se
用H5表單屬性製作簡易的登陸介面
今天學了H5新增的表單屬性,知道如何用新增的那些屬性(如form、placeholder)製作一個建議的登陸介面。 首先,在form中用input寫一個文字框。關鍵程式碼如下: <form method="post"> 使用者名稱:<input typ
面試官問我如何用python製作一個AlphaGo,我把演算法寫的明明白白
小史是一個應屆生,雖然學的是電子專業,但是自己業餘時間看了很多網際網路與程式設計方面的書,一心想進BAT網際網路公司。 當然在學習Python的道路上肯定會困難,沒有好的學習資料,怎麼去學習呢? 學習Python中有不明白推薦加入交流群 &
學習用AG真人介面BBIN介面對接平臺製作一個最簡單的飛機遊戲
第一步AG真人介面BBIN介面對接平臺q-2747044651,控制飛機移動還記得小時候玩的飛機大戰遊戲嗎?按a、s、d、w鍵後控制飛機的上下左右移動。在這裡我們通過按a、s、d、w鍵來改變座標x,y的值,從而控制飛機的移動。下面是程式碼: (小編推薦一個學C語言/C++的學習群:788649720,入群即
python的強大果然是名副其實,製作一個大資料搜尋引擎跟玩一樣!
搜尋是大資料領域裡常見的需求。Splunk和ELK分別是該領域在非開源和開源領域裡的領導者。本文利用很少的Python程式碼實現了一個基本的資料搜尋功能,試圖讓大家理解大資料搜尋的基本原理。 學習Python中有不明白推薦加入交流群
python製作一個微信機器人,陪你在繁瑣的生活裡,空一點時間
今天在簡書上看到一篇講python做微信機器人的文章,實在是感興趣,就跟著做了一下,拿來和同學玩一玩。不過在查問題的時候在網上碰到一模一樣的文章,我也不知道哪個是原創,有興趣的小夥伴可以去看一下。 不過要注意的是,那裡面有一個問題:取出字典資訊的時候把items寫成了iteri
利用python製作一個聊天機器人
該程式基於TCP服務,首先上一下成果圖 先是利用手機和服務端聊天(手機端用的是QPython3執行的python程式碼): 當然也可以在電腦上執行: 程式碼如下: 首先是服務端的