tkinter Combobox组件

来源(博客频道 - CSDN.NET)

From: http://blog.csdn.net/sofeien/article/details/49444001

tkinter Combobox组件

标签: tkinter Python Combobox

2015-10-27 09:32 2781人阅读

分类: python(59)

Combobox

values 设定可选内容

state 设定状态。readonly时只可选择,不可更改内容

.current 设定选择内容,参数为可选列表的0-index

有虚拟事件 "<ComboboxSelected>" 当列表选择时触发绑定函数

#!/usr/bin/env python3
# coding=utf-8

from tkinter import *
from tkinter import ttk

__author__ = 'Administrator'

def show_msg(*args):
	print(players.get())

root = Tk()
name = StringVar()
players = ttk.Combobox(root, textvariable=name)
players["values"] = ("成龙", "刘德华", "周星驰")
players["state"] = "readonly"

players.current(2)
# players.set("演员表")
# print(players.get())

players.bind("<<ComboboxSelected>>", show_msg)

players.pack()
root.mainloop()

Link: http://www.asm32.net/article_details.aspx?id=7245


浏览次数 0 发布时间 2017-06-26 23:57:48 从属分类 Python 【评论】【 】【打印】【关闭
 
| www.asm32.net | 2006版 | 资料中心 | linux | asm/asm32 | C/C++ | VC++ | java | Python | 书签 | ASP.Net书签 | 京ICP备09029108号-1