python的GUI編程(Tkinter庫)(三)

來源:互聯網
上載者:User
訊息(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()

結果:

點擊相關操作:

繼續:

繼續:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.