Python Tkinter基礎控制項用法_python

來源:互聯網
上載者:User

本文執行個體展示了Python Tkinter基礎控制項的用法,分享給大家供大家參考之用。具體方法如下:

# -*- 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號視窗')  Label(top, text='這是2號視窗').pack()root = Tk()root.title('1號視窗')# 顯示內建圖片# x = Label(root, bitmap='warning')l = Label(root, fg='red', bg='blue',text='wangwei', width=34, height=10)l.pack()# command 指定按鈕調用的函數b = Button(root, text='clickme', command=btn_click)b['width'] = 10b['height'] = 2b.pack()# 使用bind 方式關聯按鈕和函數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)# 擷取滑鼠左鍵點擊的座標def get_clickpoint(event):  print event.x, event.y# framefor x in ['red', 'blue', 'yellow']:  Frame(height = 20, width = 20, bg = x).pack()root['menu'] = xmenuroot.bind('<Button-3>', pop)root.bind('<Button-1>', get_clickpoint)root.mainloop()

運行效果如下圖所示:

希望本文所述對大家的Python程式設計有所協助。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.