欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

在python tkinter界面中添加按鈕的實(shí)例

 更新時(shí)間:2020年03月04日 15:39:30   作者:austin1000  
今天小編就為大家分享一篇在python tkinter界面中添加按鈕的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧

tkinter是python自帶的GUI庫,可以實(shí)現(xià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ǔ)充知識:Python筆記之Tkinter(Spinbox數(shù)值框帶加減按鈕)

一、目標(biāo)

學(xué)習(xí)Tkinter制作窗體軟件的基礎(chǔ),Spinbox,此功能可以做出比如游戲里的購物數(shù)量加減。

二、試驗(yàn)平臺

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, 開始值為0
to=100  結(jié)束值設(shè)定為100
increment=10 設(shè)定步長為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))  # #值寫死
sb.pack()
 
# xVariable.set(18)            # #賦值
# result = xVariable.get(xVariable)    # #取值
# print(result)
 
win.mainloop()  # #窗口持久化

以上這篇在python tkinter界面中添加按鈕的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論