當前位置:首頁 » 編程語言 » 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中,這行代碼一定要加

熱點內容
loggerjava 發布:2025-03-13 19:54:36 瀏覽:708
android標題欄隱藏 發布:2025-03-13 19:54:35 瀏覽:677
企業網站資料庫設計 發布:2025-03-13 19:48:18 瀏覽:465
絕對素數c語言 發布:2025-03-13 19:48:16 瀏覽:788
java工程師簡歷 發布:2025-03-13 19:42:33 瀏覽:456
我的世界2b2t伺服器海上農場 發布:2025-03-13 19:25:33 瀏覽:993
人工智慧安卓主板哪個好 發布:2025-03-13 19:15:16 瀏覽:237
android系統程序 發布:2025-03-13 19:12:15 瀏覽:37
如何修改樂視賬號密碼 發布:2025-03-13 18:56:12 瀏覽:971
c編程書籍 發布:2025-03-13 18:51:49 瀏覽:450