Python Tkinter基礎(chǔ)控件用法
本文實(shí)例展示了Python Tkinter基礎(chǔ)控件的用法,分享給大家供大家參考之用。具體方法如下:
# -*- coding: utf-8 -*-
from Tkinter import *
def btn_click():
b2['text'] = 'clicked'
evalue = e.get()
print 'btn Click and Entry value is %s' % evalue
def btn_click_bind(event):
print 'enter b2'
def show_toplevel():
top = Toplevel()
top.title('2號(hào)窗口')
Label(top, text='這是2號(hào)窗口').pack()
root = Tk()
root.title('1號(hào)窗口')
# 顯示內(nèi)置圖片
# x = Label(root, bitmap='warning')
l = Label(root, fg='red', bg='blue',text='wangwei', width=34, height=10)
l.pack()
# command 指定按鈕調(diào)用的函數(shù)
b = Button(root, text='clickme', command=btn_click)
b['width'] = 10
b['height'] = 2
b.pack()
# 使用bind 方式關(guān)聯(lián)按鈕和函數(shù)
b2 = Button(root, text = 'clickme2')
b2.configure(width = 10, height = 2, state = 'disabled')
b2.bind("<Enter>", btn_click_bind)
b2.pack()
# 彈出Toplevel窗口
b3 = Button(root, text = 'showToplevel', command=show_toplevel)
b3.pack()
# 輸入框
e = Entry(root, text = 'input your name')
e.pack()
# 密碼框
epwd = Entry(root, text = 'input your pwd', show = '*')
epwd.pack()
# 菜單
def menu_click():
print 'I am menu'
xmenu = Menu(root)
submenu = Menu(xmenu, tearoff = 0)
for item in ['java', 'cpp', 'c', 'php']:
xmenu.add_command(label = item, command = menu_click)
for item in ['think in java', 'java web', 'android']:
submenu.add_command(label = item, command = menu_click)
xmenu.add_cascade(label = 'progame', menu = submenu)
# 彈出菜單
def pop(event):
submenu.post(event.x_root, event.y_root)
# 獲取鼠標(biāo)左鍵點(diǎn)擊的坐標(biāo)
def get_clickpoint(event):
print event.x, event.y
# frame
for x in ['red', 'blue', 'yellow']:
Frame(height = 20, width = 20, bg = x).pack()
root['menu'] = xmenu
root.bind('<Button-3>', pop)
root.bind('<Button-1>', get_clickpoint)
root.mainloop()
運(yùn)行效果如下圖所示:

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
- python3使用tkinter實(shí)現(xiàn)ui界面簡(jiǎn)單實(shí)例
- Python Tkinter簡(jiǎn)單布局實(shí)例教程
- python的tkinter布局之簡(jiǎn)單的聊天窗口實(shí)現(xiàn)方法
- 對(duì)python Tkinter Text的用法詳解
- 詳解python tkinter模塊安裝過程
- 使用Python中的tkinter模塊作圖的方法
- Python 窗體(tkinter)按鈕 位置實(shí)例
- 基于python的Tkinter實(shí)現(xiàn)一個(gè)簡(jiǎn)易計(jì)算器
- python中tkinter簡(jiǎn)要教程(小白必看)
相關(guān)文章
Python批量將Word文件轉(zhuǎn)為PDF文件的實(shí)現(xiàn)示例
如果想要批量把Word文檔轉(zhuǎn)換為PDF文檔,我們可以使用第三方模塊win32com,本文就來詳細(xì)的介紹一下Python批量將Word文件轉(zhuǎn)為PDF文件的實(shí)現(xiàn)示例,感興趣的可以了解一下2023-08-08
python微信公眾號(hào)之關(guān)注公眾號(hào)自動(dòng)回復(fù)
這篇文章主要為大家詳細(xì)介紹了python微信公眾號(hào)之關(guān)注公眾號(hào)自動(dòng)回復(fù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-10-10
使用Numpy讀取CSV文件,并進(jìn)行行列刪除的操作方法
今天小編就為大家分享一篇使用Numpy讀取CSV文件,并進(jìn)行行列刪除的操作方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-07-07
詳解python 破解網(wǎng)站反爬蟲的兩種簡(jiǎn)單方法
這篇文章主要介紹了詳解python 破解網(wǎng)站反爬蟲的兩種簡(jiǎn)單方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02
詳解Python中 __get__和__getattr__和__getattribute__的區(qū)別
__get__、__getattr__、__getattribute都是訪問屬性的方法,但作用不太相同,這里我們就來詳解Python中 __get__和__getattr__和__getattribute__的區(qū)別:2016-06-06
Python GUI自動(dòng)化實(shí)現(xiàn)繞過驗(yàn)證碼登錄
這篇文章主要介紹了python GUI自動(dòng)化實(shí)現(xiàn)繞過驗(yàn)證碼登錄,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-01-01

