當前位置:首頁 » 編程語言 » pythonbutton

pythonbutton

發布時間: 2023-09-01 05:48:57

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組件製作按鈕,就分享到這里!

Ⅱ python中button跳轉下一頁

python中button跳轉下一頁
主要是通過一個按鈕進行跳轉,在點擊該按鈕時關閉當前界面,打開新界面。

主要函數doClose 按鈕觸發的函數QU

主要代碼:import wx

import pymysql,time,threading

from MySQL import Make_bill,function

class Withdrawal1(wx.App):

def doClose(self,j):

Ⅲ 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中,這行代碼一定要加

熱點內容
副編譯 發布:2025-02-04 02:05:25 瀏覽:613
解壓按摩師 發布:2025-02-04 01:21:31 瀏覽:424
linuxssh限制 發布:2025-02-04 01:20:40 瀏覽:697
腳本式是什麼 發布:2025-02-04 01:06:24 瀏覽:248
手機wps密碼怎麼取消密碼 發布:2025-02-04 00:51:44 瀏覽:596
演算法邏輯表 發布:2025-02-04 00:51:44 瀏覽:241
零售股票如何配置主線 發布:2025-02-04 00:51:07 瀏覽:948
預演算法施行時間是 發布:2025-02-04 00:50:30 瀏覽:343
世界ol上傳照片 發布:2025-02-04 00:34:13 瀏覽:63
有初始化的數組編譯提示重復定義 發布:2025-02-04 00:33:21 瀏覽:584