在python tkinter界面中添加按鈕的實例
tkinter是python自帶的GUI庫,可以實現(xiàn)簡單的GUI交互,該例子添加了五種不同效果的Button,如圖:
from tkinter import *from tkinter import messagebox #python3.0的messagebox,屬于tkinter的一個組件 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ǔ)充知識:Python筆記之Tkinter(Spinbox數(shù)值框帶加減按鈕)
一、目標(biāo)
學(xué)習(xí)Tkinter制作窗體軟件的基礎(chǔ),Spinbox,此功能可以做出比如游戲里的購物數(shù)量加減。
二、試驗平臺
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')’’’此功能可以做出比如游戲里的購物數(shù)量加減。from_=0, 開始值為0to=100 結(jié)束值設(shè)定為100increment=10 設(shè)定步長為10,默認(rèn)為1。values=(0, 2, 4, 6, 8, 21, 37, 36) 可以設(shè)定值是固定的哪些,用了這玩意就不能用from_ to了’’’xVariable = tkinter.StringVar() # #設(shè)定一個字符串類型的變量 # #創(chuàng)建scale滾動條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)) # #值寫死sb.pack() # xVariable.set(18) # #賦值# result = xVariable.get(xVariable) # #取值# print(result) win.mainloop() # #窗口持久化
以上這篇在python tkinter界面中添加按鈕的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP實現(xiàn)加法驗證碼2. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)3. javascript xml xsl取值及數(shù)據(jù)修改第1/2頁4. 怎樣才能用js生成xmldom對象,并且在firefox中也實現(xiàn)xml數(shù)據(jù)島?5. 小技巧處理div內(nèi)容溢出6. JSP實現(xiàn)文件上傳功能7. JavaWeb Servlet中url-pattern的使用8. asp知識整理筆記4(問答模式)9. JSP+Servlet實現(xiàn)文件上傳到服務(wù)器功能10. jsp+servlet實現(xiàn)猜數(shù)字游戲
