最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解python3 GUI刷屏器(附源碼)

 更新時間:2021年02月18日 11:46:05   作者:懷淰メ  
這篇文章主要介紹了詳解python3 GUI刷屏器(附源碼),本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

過年GUI博客二連發(fā),本打算出去玩玩,奈何空氣,天氣實在差,遂使用tkinter開發(fā)一款GUI刷屏器,寫此博客記錄一下我的開發(fā)思路。

一.準備工作

本次使用除tkinter庫之外還使用了pynput庫,可以使用

pip install pynput

安裝

二.預(yù)覽

在這里插入圖片描述

在長文本框中輸入要刷屏的內(nèi)容,通過設(shè)置刷屏頻率(單位:秒)即可實現(xiàn)刷屏。

三.設(shè)計流程

在這里插入圖片描述

四.源代碼

import re
import time
import pyperclip
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
from pynput.keyboard import Key, Controller
import threading
from PIL import Image ,ImageTk

'''
難點
按鍵復(fù)用
'''

imgs=["./rely/logo.png",'./rely/favicon.ico']
class App:
 def __init__(self):
  self.flag=True
  self.window = Tk()
  width = 230
  height = 260
  screenWidth = self.window.winfo_screenwidth() # 獲取顯示區(qū)域的寬度
  screenHeight = self.window.winfo_screenheight() # 獲取顯示區(qū)域的高度
  left = (screenWidth - width) / 2
  top = (screenHeight - height) / 2
  self.window.geometry("%dx%d+%d+%d" % (width, height, left, top))
  self.window.title('刷一刷-v1.0')
  self.window.iconbitmap(imgs[1])
  self.window.resizable(0, 0)
  self.create_widget()
  self.config_widget()
  self.place_widget()
  self.window.mainloop()

 def create_widget(self):
  self.paned=PanedWindow(self.window)
  self.img=imgs
  photo = Image.open(self.img[0]) # 括號里為需要顯示在圖形化界面里的圖片
  photo = photo.resize((150, 50)) # 規(guī)定圖片大小
  self.paned.img = ImageTk.PhotoImage(photo)
  self.l0 = Label(self.window, image=self.paned.img, justify='center')
  self.l1 = ttk.Label(self.window, text='內(nèi)容:')
  self.l1 = ttk.Label(self.window, text='頻率:')
  self.t1 = Text(self.window)
  self.c1 = ttk.Combobox(self.window, width=13)
  self.l2=ttk.Label(self.window,text='秒/次')
  self.b1 = ttk.Button(self.window, text='開始', )
  self.b2 = ttk.Button(self.window, text='退出',)
  self.m=Menu(self.window)
  self.window['menu']=self.m
  self.s1=Menu(self.m,tearoff=False)
  self.s2=Menu(self.m,tearoff=False)
  self.s3=Menu(self.m,tearoff=False)

 def place_widget(self):
  self.l0.pack()
  self.l1.place(x=20, y=90)
  self.t1.place(x=40, y=60, width=150, height=80)
  self.l1.place(x=20, y=162)
  self.c1.place(x=65, y=160,width=80)
  self.l2.place(x=160,y=160)
  self.b1.place(x=20, y=200)
  self.b2.place(x=125, y=200)

 def config_widget(self):
  self.b1.config(command=lambda: self.thread_it(self.start))
  self.b2.config( command=self.window_quit)
  rate_list=['1','0.1','0.01']
  self.c1.config(value=rate_list)
  self.m.add_cascade(label='文件',menu=self.s1)
  self.s1.add_command(label='退出',command=self.window_quit)
  self.m.add_cascade(label='操作',menu=self.s2)
  self.m.add_cascade(label='關(guān)于',menu=self.s3)
  self.s2.add_command(label='開始 F9',command=lambda: self.thread_it(self.start))
  self.s2.add_command(label='停止 F10',command=lambda: self.thread_it(self.start))
  self.s3.add_command(label='說明',command=self.show_infos)
  #設(shè)置熱鍵
  self.window.bind('<F9>',lambda: self.thread_it(self.pre_start))
  self.window.bind('<F10>',lambda: self.thread_it(self.pre_start))
  self.window.bind('<Escape>',self.escape)
  self.window.bind('<FocusIn>',self.clear_content)
  self.window.protocol('WM_DELETE_WINDOW',self.window_quit)

 def clear_content(self,event):
  self.t1.delete(0.0,END)

 def pre_start(self,event):
  self.start()

 def start(self):
  if self.b1['text']=='開始':
   self.flag=True
   t1_content = self.t1.get(1.0, 'end').strip()
   if len(t1_content) != 0:
    gap = self.c1.get()
    try:
     if re.match('(^0|^1)\.{0,1}\d+$', gap) or int(gap) > 0:
      # 將t1內(nèi)容復(fù)制到剪切板
      pyperclip.copy(t1_content)
      keyboard = Controller()
      self.b1.config(text='停止')
      self.t1.config(state='disable')
      while True:
       # 使用control+v組合鍵進行粘貼
       if self.flag:
        keyboard.press(Key.ctrl.value)
        keyboard.press('v')
        keyboard.release('v')
        keyboard.release(Key.ctrl.value)
        keyboard.press(Key.enter.value)
        keyboard.release(Key.enter.value)
        print(t1_content)
        time.sleep(float(gap))
       else:
        break
     else:
      messagebox.showerror('錯誤', '請輸入正確的數(shù)值!')
      self.c1.delete(0, END)
    except ValueError:
     messagebox.showerror('錯誤', '請輸入正確的數(shù)值!')
     self.c1.delete(0, END)
   else:
    messagebox.showerror('錯誤', '還沒有輸入內(nèi)容')
  else:
   self.flag=False
   self.b1.config(text='開始')

 def thread_it(self,func,*args):
  t=threading.Thread(target=func,args=args)
  t.setDaemon(True)#設(shè)置守護線程,即主線程結(jié)束,子線程也結(jié)束
  t.start()

 def show_infos(self):
  messagebox.showinfo('說明','***本軟件完全免費***\n\n1.輸入刷屏內(nèi)容\n2.選擇(輸入)刷屏頻率\n3.開始(F9)刷屏\n4.停止(F10)刷屏')

 def window_quit(self):
  ret=messagebox.askyesno('退出','是否要退出?')
  if ret:
   self.window.destroy()

 def escape(self,event):
  self.window_quit()


if __name__ == '__main__':
 a=App()

五.總結(jié)

本次使用tkinter寫了一款刷屏器,能夠?qū)崿F(xiàn)短時間內(nèi)相同文本的發(fā)送,繼而實現(xiàn)刷屏的目的。在代碼的撰寫上,模擬鍵盤輸入主要參考了:

python模擬鼠標點擊和鍵盤輸入的操作

實現(xiàn)了組合鍵Ctrl+V的操作。本篇技術(shù)含量不多,重點在代碼邏輯思路上。

到此這篇關(guān)于python3 GUI刷屏器(附源碼)的文章就介紹到這了,更多相關(guān)python刷屏器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 對pandas中時間窗函數(shù)rolling的使用詳解

    對pandas中時間窗函數(shù)rolling的使用詳解

    今天小編就為大家分享一篇對pandas中時間窗函數(shù)rolling的使用詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-11-11
  • numpy工程實踐之np.savetxt()存儲數(shù)據(jù)

    numpy工程實踐之np.savetxt()存儲數(shù)據(jù)

    NumPy提供了多種存取數(shù)組內(nèi)容的文件操作函數(shù),保存數(shù)組數(shù)據(jù)的文件可以是二進制格式或者文本格式,下面這篇文章主要給大家介紹了關(guān)于numpy工程實踐之np.savetxt()存儲數(shù)據(jù)的相關(guān)資料,需要的朋友可以參考下
    2023-05-05
  • 關(guān)于python中time和datetime的區(qū)別與用法

    關(guān)于python中time和datetime的區(qū)別與用法

    這篇文章主要介紹了關(guān)于python中time和datetime的區(qū)別與用法,Python中封裝了很多實用的函數(shù),那么關(guān)于時間的函數(shù)time和datetime有什么區(qū)別和作用,讓我們來看看吧
    2023-03-03
  • python使用py2neo查詢Neo4j的節(jié)點、關(guān)系及路徑

    python使用py2neo查詢Neo4j的節(jié)點、關(guān)系及路徑

    本文介紹了使用Py2neo的NodeMatcher和RelationshipMatcher查詢圖中的節(jié)點和關(guān)系,以及通過執(zhí)行Cypher語句的查詢方式。感興趣的小伙伴請看下文
    2021-08-08
  • python實現(xiàn)連續(xù)變量最優(yōu)分箱詳解--CART算法

    python實現(xiàn)連續(xù)變量最優(yōu)分箱詳解--CART算法

    今天小編就為大家分享一篇python實現(xiàn)連續(xù)變量最優(yōu)分箱詳解--CART算法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • python虛擬環(huán)境模塊venv使用及示例

    python虛擬環(huán)境模塊venv使用及示例

    這篇文章主要介紹了python虛擬環(huán)境模塊venv,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • 圖文詳解matlab原始處理圖像幾何變換

    圖文詳解matlab原始處理圖像幾何變換

    Matlab 擅長于操作矩陣,而圖像其實就是矩陣,這篇文章主要給大家介紹了關(guān)于matlab原始處理圖像幾何變換的相關(guān)資料,需要的朋友可以參考下
    2021-07-07
  • Python如何實現(xiàn)MySQL實例初始化詳解

    Python如何實現(xiàn)MySQL實例初始化詳解

    這篇文章主要給大家介紹了關(guān)于Python如何實現(xiàn)MySQL實例初始化的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • python-opencv-cv2.threshold()二值化函數(shù)的使用

    python-opencv-cv2.threshold()二值化函數(shù)的使用

    這篇文章主要介紹了python-opencv-cv2.threshold()二值化函數(shù)的使用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • selenium+Chrome滑動驗證碼破解二(某某網(wǎng)站)

    selenium+Chrome滑動驗證碼破解二(某某網(wǎng)站)

    這篇文章主要介紹了selenium+Chrome滑動驗證碼破解二(某某網(wǎng)站),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12

最新評論

白银市| 宜君县| 鄱阳县| 财经| 台州市| 昌都县| 彰武县| 九江县| 潢川县| 社会| 仪陇县| 余姚市| 信丰县| 大足县| 东莞市| 县级市| 治多县| 乐东| 渭南市| 观塘区| 夏河县| 苗栗县| 博湖县| 寻甸| 东城区| 神木县| 宁阳县| 横峰县| 无极县| 冕宁县| 东乌珠穆沁旗| 嘉黎县| 东兴市| 东港市| 大新县| 新干县| 江达县| 东辽县| 宁远县| 芮城县| 来宾市|