導航:首頁 > 編程語言 > python拖拉按鈕

python拖拉按鈕

發布時間:2023-09-17 12:16:37

A. python怎麼設置button按鈕

生活中我們會遇到各種各樣的登錄界面,比如在登陸QQ時將賬號和密碼輸入完備後,需要點擊「登錄」才能進入到自己的QQ頁面。在Python中,這里的「登錄」就是用Button組件製作的一個按鈕。

導入tkinter模塊
from tkinter import*
定義函數,用於在shell頁面回答按鈕上面的問題
def answer(): print("你看我像靚仔嗎?")
創建根窗口
root=Tk()
創建Button組件
button=Button(root,text="你是靚仔嗎",command=answer)#創建變數用於存放Button以及Button中的參數,root為根窗口,text為按鈕上的文本內容,command=answer的作用是將按鈕與函數綁定在一起
在根窗口中展示Button組件
button.pack()
讓根窗口持續展示
root.mainloop()
完整代碼
from tkinter import*def answer(): print("你看我像靚仔嗎?")root=Tk()button=Button(root,text="你是靚仔嗎",command=answer)button.pack()root.mainloop()
成果展示

使用Python中的Button組件製作按鈕,就分享到這里!

B. pythondocx添加按鈕

在WORD中通過滑鼠右鍵菜單「插入」按鈕中的功能可以實現表格行列的添加,也可以通過「刪除單元格」按鈕中的刪除單元格的功能實現表格行列的刪除;當然還可以通過「布局」菜單中的刪除和添加功能實現。

C. pythonmain.exe上有按鈕

水平有限,歡迎建議和挑錯

PyQt5中按鈕是一個QpushButton,可以提供一個點擊的按鈕來觸發摸一個事件。

按鈕可以顯示圖片或者文字。

創建按鈕

我們在第一節的mainwindow上創建一個按鈕,代碼如下:

from PyQt5 import QtCore, QtGui, QtWidgets

from PyQt5.QtGui import QIcon

class Ui_mainWindow(object):

def setupUi(self, mainWindow):

mainWindow.setObjectName("mainWindow")

mainWindow.setWindowModality(QtCore.Qt.WindowModal)

mainWindow.resize(624, 511)

self.centralWidget = QtWidgets.QWidget(mainWindow)

self.centralWidget.setObjectName("centralWidget")

self.pushButton = QtWidgets.QPushButton(self.centralWidget)

self.pushButton.setGeometry(QtCore.QRect(240, 240, 75, 23))

self.pushButton.setObjectName("pushButton")

mainWindow.setCentralWidget(self.centralWidget)

self.retranslateUi(mainWindow)

QtCore.QMetaObject.connectSlotsByName(mainWindow)

def retranslateUi(self, mainWindow):

_translate = QtCore.QCoreApplication.translate

mainWindow.setWindowTitle('您好')

mainWindow.setWindowIcon(QIcon('logo.png'))

if __name__ == "__main__":

import sys

app = QtWidgets.QApplication(sys.argv)

mainWindow = QtWidgets.QMainWindow()

ui = Ui_mainWindow()

ui.setupUi(mainWindow)

mainWindow.show()

sys.exit(app.exec_())

image

這里只是單單創建一個按鈕,按鈕點擊並沒有任何作用。

同樣按鈕也可以進行各種設置。

image

除了上圖幾種方法,再介紹另外幾種方法。

(1)設置字體大小,加粗,字型

font = QtGui.QFont()

font.setFamily('微軟雅黑')

font.setBold(True)

font.setPointSize(13)

font.setWeight(75)

self.pushButton.setFont(font)

這個方法是通用的。幾乎PyQt其他組件也能用。

image

(2)設置圖片

icon = QtGui.QIcon()

icon.addPixmap(QtGui.QPixmap("logo.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)

self.pushButton.setIcon(icon)

self.pushButton.setIconSize(QtCore.QSize(50, 80))

self.pushButton.setAutoRepeatDelay(200)

image

無圖代碼

from PyQt5 import QtCore, QtGui, QtWidgets

from PyQt5.QtGui import QIcon

class Ui_mainWindow(object):

def setupUi(self, mainWindow):

mainWindow.setObjectName("mainWindow")

mainWindow.setWindowModality(QtCore.Qt.WindowModal)

mainWindow.resize(624, 511)

self.centralWidget = QtWidgets.QWidget(mainWindow)

self.centralWidget.setObjectName("centralWidget")

self.pushButton = QtWidgets.QPushButton(self.centralWidget)

self.pushButton.setGeometry(QtCore.QRect(240, 240,200, 53))

self.pushButton.setObjectName("pushButton")

self.pushButton.setText("一顆數據小白菜")

# self.pushButton.setFlat(True)

self.pushButton.setStyleSheet("background-color: rgb(164, 185, 255);"

"border-color: rgb(170, 150, 163);"

"font: 75 12pt \"Arial Narrow\";"

"color: rgb(126, 255, 46);")

mainWindow.setCentralWidget(self.centralWidget)

self.retranslateUi(mainWindow)

QtCore.QMetaObject.connectSlotsByName(mainWindow)

def retranslateUi(self, mainWindow):

_translate = QtCore.QCoreApplication.translate

mainWindow.setWindowTitle('您好')

mainWindow.setWindowIcon(QIcon('logo.png'))

if __name__ == "__main__":

import sys

app = QtWidgets.QApplication(sys.argv)

mainWindow = QtWidgets.QMainWindow()

ui = Ui_mainWindow()

ui.setupUi(mainWindow)

mainWindow.show()

sys.exit(app.exec_())

image

有圖代碼

from PyQt5 import QtCore, QtGui, QtWidgets

from PyQt5.QtGui import QIcon

class Ui_mainWindow(object):

def setupUi(self, mainWindow):

mainWindow.setObjectName("mainWindow")

mainWindow.setWindowModality(QtCore.Qt.WindowModal)

mainWindow.resize(624, 511)

self.centralWidget = QtWidgets.QWidget(mainWindow)

self.centralWidget.setObjectName("centralWidget")

self.pushButton = QtWidgets.QPushButton(self.centralWidget)

self.pushButton.setGeometry(QtCore.QRect(240, 240,200, 53))

self.pushButton.setObjectName("pushButton")

self.pushButton.setText("一顆數據小白菜")

# self.pushButton.setFlat(True)

self.pushButton.setStyleSheet("background-color: rgb(164, 185, 255);"

"border-color: rgb(170, 150, 163);"

"font: 75 12pt \"Arial Narrow\";"

"color: rgb(126, 255, 46);")

icon = QtGui.QIcon()

icon.addPixmap(QtGui.QPixmap("logo.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)

self.pushButton.setIcon(icon)

self.pushButton.setIconSize(QtCore.QSize(50, 80))

self.pushButton.setAutoRepeatDelay(200)

mainWindow.setCentralWidget(self.centralWidget)

self.retranslateUi(mainWindow)

QtCore.QMetaObject.connectSlotsByName(mainWindow)

def retranslateUi(self, mainWindow):

_translate = QtCore.QCoreApplication.translate

mainWindow.setWindowTitle('您好')

mainWindow.setWindowIcon(QIcon('logo.png'))

if __name__ == "__main__":

import sys

app = QtWidgets.QApplication(sys.argv)

mainWindow = QtWidgets.QMainWindow()

ui = Ui_mainWindow()

ui.setupUi(mainWindow)

mainWindow.show()

sys.exit(app.exec_())

image

綁定按鈕事件

我們給按鈕綁定觸發時間,用:

pushbutton.clicked.connect()

(1)退出事件

我們給按鈕綁定退出事件:

self.pushButton.clicked.connect(mainWindow.close)

image

D. python腳本如何添加啟動和停止按鈕

用tkinter的button組件。
設定好字體大小size(int類型),在循環內部(以while舉例)加組件:

xunhuan=1 # 控制循環的開始與結束
# 定義開始循環
def start():
global xunhuan

xunhuan = 1

# 結束
def end():
global xunhuan

xunhuan = 0

size=(字的大小)
# 現在導庫
inport tkinter as tk # 輸入方便
window = tk.Tk()
s = tk.Button(window, text = "開始" , command = start) # 開始按鈕
e = tk.Button(window , text = "停止" , command = end) # 結束按鈕
# 繪制按鈕
s.pack()
e.pack()
# 下面是循環
while True:
if xunhuan:

...(循環內部要做的事)

window.mainloop() # 在tkinter中,這行代碼一定要加

E. 能不能做一個html頁面,然後按鈕的功能用python實現

你好 可以的,不過你需要會javascript和AJAX,AJAX可以在不刷新網頁的情況下把數據傳給後端,你可以通過HTML來定義按鈕,然後通過javascript定義按鈕事件,然後通過AJAX把數據傳給後端,後端用Python處理後在把數據傳給前端,如果你對javascript還不是太熟練的話可以使用jQuery這個javascript庫,jQuery簡化了很多原生javascript復雜的部分。不過如果你需要的功能能在前端實現的話就盡量不要讓後端來作,除非是必須要提交數據給後端處理,因為每次提交數據給後端都要耗費一定的時間,如果遇上網路不好的情況體驗會比較差。希望我的回答能夠幫助到你,如果還有什麼疑問可以繼續追問。

閱讀全文

與python拖拉按鈕相關的資料

熱點內容
linux登錄失敗次數 瀏覽:33
linuxread0 瀏覽:332
三軌直銷系統源碼 瀏覽:321
手機銀行app怎麼更新呢 瀏覽:247
單片機匯編學習 瀏覽:531
配1u伺服器主機需要注意什麼 瀏覽:38
演算法工程師小李 瀏覽:633
程序員搬到哪裡買房好 瀏覽:627
steam測試亞洲伺服器怎麼切換 瀏覽:513
vc命令行編譯工程 瀏覽:331
當貝市場解壓步驟 瀏覽:458
哪裡有賣安卓系統的app 瀏覽:472
河南省雲伺服器租賃雲主機 瀏覽:755
基金app哪個好2021年 瀏覽:41
迷你電梯單片機 瀏覽:38
編譯電腦 瀏覽:502
程序員進入網吧 瀏覽:247
cad圖轉換pdf 瀏覽:809
魔域單機版命令 瀏覽:488
ftp伺服器需要開放什麼埠 瀏覽:327