ComboBox怎么在Python項(xiàng)目中使用-創(chuàng)新互聯(lián)

ComboBox怎么在Python項(xiàng)目中使用?相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。

站在用戶的角度思考問題,與客戶深入溝通,找到藁城網(wǎng)站設(shè)計(jì)與藁城網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、申請(qǐng)域名、網(wǎng)頁空間、企業(yè)郵箱。業(yè)務(wù)覆蓋藁城地區(qū)。

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)丶輕語') # 標(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, # 通過StringVar設(shè)置可改變的值
      values=values, # 設(shè)置下拉框的選項(xiàng)
      )
  print(combobox.keys()) # 可以查看支持的參數(shù)
  combobox.pack()
  win.mainloop()

ComboBox怎么在Python項(xiàng)目中使用

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)丶輕語') # 標(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, # 通過StringVar設(shè)置可改變的值
      values=values, # 設(shè)置下拉框的選項(xiàng)
      )
  combobox.bind('<<ComboboxSelected>>', choose)
  print(combobox.keys()) # 可以查看支持的參數(shù)
  combobox.pack()
  win.mainloop()

ComboBox怎么在Python項(xiàng)目中使用

看完上述內(nèi)容,你們掌握ComboBox怎么在Python項(xiàng)目中使用的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

當(dāng)前標(biāo)題:ComboBox怎么在Python項(xiàng)目中使用-創(chuàng)新互聯(lián)
文章鏈接:http://muchs.cn/article18/dphcgp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、外貿(mào)建站電子商務(wù)、網(wǎng)站導(dǎo)航、自適應(yīng)網(wǎng)站域名注冊(cè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)