最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python tkinter之ComboBox(下拉框)的使用簡(jiǎn)介

 更新時(shí)間:2021年02月05日 17:22:52   作者:南風(fēng)丶輕語(yǔ)  
這篇文章主要介紹了Python tkinter之ComboBox(下拉框)的使用簡(jiǎn)介,幫助大家更好的理解和使用python,感興趣的朋友可以了解下

1、ComboBox的基礎(chǔ)屬性

# -*- encoding=utf-8 -*-
import tkinter
from tkinter import *
from tkinter import ttk

if __name__ == '__main__':
  win = tkinter.Tk() # 窗口
  win.title('南風(fēng)丶輕語(yǔ)') # 標(biāo)題
  screenwidth = win.winfo_screenwidth() # 屏幕寬度
  screenheight = win.winfo_screenheight() # 屏幕高度
  width = 600
  height = 500
  x = int((screenwidth - width) / 2)
  y = int((screenheight - height) / 2)
  win.geometry('{}x{}+{}+{}'.format(width, height, x, y)) # 大小以及位置
  value = StringVar()
  value.set('CCC')
  values = ['AAA', 'BBB', 'CCC', 'DDD']
  combobox = ttk.Combobox(
      master=win, # 父容器
      height=10, # 高度,下拉顯示的條目數(shù)量
      width=20, # 寬度
      state='readonly', # 設(shè)置狀態(tài) normal(可選可輸入)、readonly(只可選)、 disabled
      cursor='arrow', # 鼠標(biāo)移動(dòng)時(shí)樣式 arrow, circle, cross, plus...
      font=('', 20), # 字體
      textvariable=value, # 通過(guò)StringVar設(shè)置可改變的值
      values=values, # 設(shè)置下拉框的選項(xiàng)
      )
  print(combobox.keys()) # 可以查看支持的參數(shù)
  combobox.pack()
  win.mainloop()

2、綁定選中事件

# -*- encoding=utf-8 -*-
import tkinter
from tkinter import *
from tkinter import ttk


def choose(event):
  # 選中事件
  print('選中的數(shù)據(jù):{}'.format(combobox.get()))
  print('value的值:{}'.format(value.get()))


if __name__ == '__main__':
  win = tkinter.Tk() # 窗口
  win.title('南風(fēng)丶輕語(yǔ)') # 標(biāo)題
  screenwidth = win.winfo_screenwidth() # 屏幕寬度
  screenheight = win.winfo_screenheight() # 屏幕高度
  width = 600
  height = 500
  x = int((screenwidth - width) / 2)
  y = int((screenheight - height) / 2)
  win.geometry('{}x{}+{}+{}'.format(width, height, x, y)) # 大小以及位置
  value = StringVar()
  value.set('CCC') # 默認(rèn)選中CCC==combobox.current(2)

  values = ['AAA', 'BBB', 'CCC', 'DDD']
  combobox = ttk.Combobox(
      master=win, # 父容器
      height=10, # 高度,下拉顯示的條目數(shù)量
      width=20, # 寬度
      state='normal', # 設(shè)置狀態(tài) normal(可選可輸入)、readonly(只可選)、 disabled
      cursor='arrow', # 鼠標(biāo)移動(dòng)時(shí)樣式 arrow, circle, cross, plus...
      font=('', 20), # 字體
      textvariable=value, # 通過(guò)StringVar設(shè)置可改變的值
      values=values, # 設(shè)置下拉框的選項(xiàng)
      )
  combobox.bind('<<ComboboxSelected>>', choose)
  print(combobox.keys()) # 可以查看支持的參數(shù)
  combobox.pack()
  win.mainloop()

以上就是Python tkinter之ComboBox(下拉框)的使用簡(jiǎn)介的詳細(xì)內(nèi)容,更多關(guān)于Python tkinter之ComboBox 下拉框的使用的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論

西宁市| 确山县| 海门市| 鸡西市| 建昌县| 城固县| 隆化县| 苏尼特右旗| 中西区| 六安市| 江永县| 无棣县| 德阳市| 海南省| 宁陵县| 孟州市| 临武县| 仁化县| 孟津县| 梨树县| 萍乡市| 林西县| 崇阳县| 杨浦区| 辛集市| 上饶县| SHOW| 阳西县| 辽阳市| 五台县| 岗巴县| 新沂市| 杂多县| 那坡县| 安溪县| 达孜县| 江都市| 尼玛县| 奉贤区| 浪卡子县| 托克逊县|