TShopping

 找回密碼
 註冊
搜索
查看: 1473|回復: 0
打印 上一主題 下一主題

[教學] Python tkinter 如何用 combobox 做多國語言介面

[複製鏈接]
跳轉到指定樓層
1#
發表於 2021-9-4 11:06:18 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook




  1. import tkinter as tk
  2. import tkinter.ttk as ttk

  3. def combobox_selected(event):
  4.     if (comboboxText.get() == 'ch') : #選擇語言
  5.         redText.set('紅')
  6.         blueText.set('藍')
  7.     else:
  8.         redText.set('red')
  9.         blueText.set('blue')

  10. root = tk.Tk()
  11. root.title('my window')
  12. root.geometry('300x200') #視窗大小

  13. comboboxText = tk.StringVar()
  14. mycombobox = ttk.Combobox(root, textvariable=comboboxText, state='readonly')
  15. mycombobox['values'] = ["Language",'eng', 'ch']
  16. mycombobox.pack(pady=10)
  17. mycombobox.current(0)

  18. mycombobox.bind('<<ComboboxSelected>>', combobox_selected) #綁定 combobox VALUE

  19. redText = tk.StringVar() #宣告變數
  20. blueText = tk.StringVar()

  21. chk_frame = tk.Frame(root)
  22. chk_frame.pack(side=tk.TOP)

  23. chkred = tk.Checkbutton(chk_frame, textvariable=redText, var='')
  24. chkred.pack(side=tk.LEFT)
  25. chkblue = tk.Checkbutton(chk_frame, textvariable=blueText, var='')
  26. chkblue.pack(side=tk.LEFT)

  27. combobox_selected('') # 執行預設值

  28. root.mainloop() # 視窗秀出
複製代碼




 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-26 04:01 , Processed in 0.067790 second(s), 25 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表