在python tkinter界面中添加按鈕的實(shí)例
tkinter是python自帶的GUI庫(kù),可以實(shí)現(xiàn)簡(jiǎn)單的GUI交互,該例子添加了五種不同效果的Button,如圖:
from tkinter import *from tkinter import messagebox #python3.0的messagebox,屬于tkinter的一個(gè)組件 top = Tk()top.title('button test')def callback(): messagebox.showinfo('Python command','人生苦短、我用Python') Button(top, text='外觀裝飾邊界附近的標(biāo)簽', width=19,bg='red',relief='raised').pack() Button(top, text='設(shè)置按鈕狀態(tài)',width=21,state='disable').pack() Button(top, text='設(shè)置bitmap放到按鈕左邊位置', compound='left',bitmap='error').pack() Button(top, text='設(shè)置command事件調(diào)用命令', fg='blue',bd=2,width=28,command=callback).pack() Button(top, text ='設(shè)置高度寬度以及文字顯示位置',anchor = ’sw’,width = 30,height = 2).pack() top.mainloop()
補(bǔ)充知識(shí):Python筆記之Tkinter(Spinbox數(shù)值框帶加減按鈕)
一、目標(biāo)
學(xué)習(xí)Tkinter制作窗體軟件的基礎(chǔ),Spinbox,此功能可以做出比如游戲里的購(gòu)物數(shù)量加減。
二、試驗(yàn)平臺(tái)
windows7 , python3.7
三、直接上代碼
import tkinter def xFunc(): print(xVariable.get()) win = tkinter.Tk()win.title('Kahn Software v1') # #窗口標(biāo)題win.geometry('500x500+200+20')’’’此功能可以做出比如游戲里的購(gòu)物數(shù)量加減。from_=0, 開(kāi)始值為0to=100 結(jié)束值設(shè)定為100increment=10 設(shè)定步長(zhǎng)為10,默認(rèn)為1。values=(0, 2, 4, 6, 8, 21, 37, 36) 可以設(shè)定值是固定的哪些,用了這玩意就不能用from_ to了’’’xVariable = tkinter.StringVar() # #設(shè)定一個(gè)字符串類型的變量 # #創(chuàng)建scale滾動(dòng)條sb = tkinter.Spinbox(win, from_=0, to=100, increment=1, textvariable=xVariable, command=xFunc)# sb = tkinter.Spinbox(win, values=(0, 2, 4, 6, 8, 21, 37, 36)) # #值寫(xiě)死sb.pack() # xVariable.set(18) # #賦值# result = xVariable.get(xVariable) # #取值# print(result) win.mainloop() # #窗口持久化
以上這篇在python tkinter界面中添加按鈕的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. vue3+ts+elementPLus實(shí)現(xiàn)v-preview指令2. Xml簡(jiǎn)介_(kāi)動(dòng)力節(jié)點(diǎn)Java學(xué)院整理3. 使用Hangfire+.NET 6實(shí)現(xiàn)定時(shí)任務(wù)管理(推薦)4. 如何在jsp界面中插入圖片5. phpstudy apache開(kāi)啟ssi使用詳解6. jsp實(shí)現(xiàn)登錄驗(yàn)證的過(guò)濾器7. jsp文件下載功能實(shí)現(xiàn)代碼8. 詳解瀏覽器的緩存機(jī)制9. 爬取今日頭條Ajax請(qǐng)求10. xml中的空格之完全解說(shuō)
