訊息(message)
訊息控制項提供了顯示多行文本的方法,且可以設定字型和背景顏色
樣本:
from Tkinter import *root=Tk()root.title('top')Message(root,text='you can record your wonderful thing ,you can record your wonderful thing ',\ bg='blue',fg='ivory',relief=GROOVE).pack(padx=10,pady=10)root.mainloop()
結果:
列表(ListBox)
列表框組件是一個選項列表,使用者可以從中選擇某一選項
樣本:
from Tkinter import *root=Tk()root.title()l=Listbox(root,width=15)l.pack()for item in ['apple','orange','peach','banana','melon']: l.insert(END,item)root.mainloop()
結果:
捲軸(Scrollbar)
捲軸組件可以添加至任何一個組件,一些組件在介面顯示不下時會自動添加捲軸,但是可以使用捲軸組件來對其進行控制
樣本:
from Tkinter import *root=Tk()root.title('top')l=Listbox(root,height=6,width=15)scroll=Scrollbar(root,command=l.yview)l.configure(yscrollcommand=scroll.set)l.pack(side=LEFT)scroll.pack(side=RIGHT,fill=Y)for item in range(20): l.insert(END,item)root.mainloop()
結果:
訊息框(messagebox)
訊息視窗用於彈出提示框像使用者進行警告,或讓使用者選擇選擇下一步如何操作,訊息框包括很多類型,長用的有info、warning、error、yesno、OKcancel等,包含不同的的表徵圖、按鈕以及彈出提示音。
樣本:
import Tkinter as tkimport tkMessageBox as msgboxdef btn1_clicked(): msgbox.showinfo("info","showinfo test.")def btn2_clicked(): msgbox.showwarning("warning","showwarning test.")def btn3_clicked(): msgbox.showerror("error","showerror test.")def btn4_clicked(): msgbox.askquestion("question","askquestion test.")def btn5_clicked(): msgbox.askyesno("yesno","askyesno test.")def btn6_clicked(): msgbox.askokcancel("okcancel","askcancel test.")def btn7_clicked(): msgbox.askretrycancel("retry","askretrycancel test.")root=tk.Tk()root.title("Msgbox test")btn1=tk.Button(root,text="showinfo",command=btn1_clicked)btn1.pack(fill=tk.X)btn2=tk.Button(root,text="showwarning",command=btn2_clicked)btn2.pack(fill=tk.X)btn3=tk.Button(root,text="showerror",command=btn3_clicked)btn3.pack(fill=tk.X)btn4=tk.Button(root,text="showaskquestion",command=btn4_clicked)btn4.pack(fill=tk.X)btn5=tk.Button(root,text="askyesno",command=btn5_clicked)btn5.pack(fill=tk.X)btn6=tk.Button(root,text="showokcancel",command=btn6_clicked)btn6.pack(fill=tk.X)btn7=tk.Button(root,text="showretrycancel",command=btn7_clicked)btn7.pack(fill=tk.X)root.mainloop()
結果:
點擊相關操作:
繼續:
繼續: