我有一个从mysql请求提供的组合框。如果结果中有空格,则问题似乎是错误的
如果我在mysql中: 我的组合框中的test1我有test1 = OK 我的组合框中的测试2我有{测试2} =错误
#FRAME INFO
frame_info = LabelFrame (Product, text = 'Info Maker',height=240,width=1000)
frame_info.place (x=220, y=10)
combo_maker = ttk.Combobox(frame_info,state="readonly")
#combo_maker['value'] = combo_input()
combo_maker['value'] = combo_input()
combo_maker.current(0)
combo_maker.place(x=5, y=5, height = 25, width = 180)
#FRAME INFO
答案 0 :(得分:0)
您从mysql得到的结果是一个元组列表。您需要先将它们展平,然后再插入组合框。
以下内容展示了展平前后的区别:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
def combo_input():
return [('test 1',), ('test 2',), ('test3',)]
a_combo_maker = ttk.Combobox(root,state="readonly")
a_combo_maker["value"] = combo_input()
a_combo_maker.current(0)
a_combo_maker.pack()
b_combo_maker = ttk.Combobox(root,state="readonly")
b_combo_maker["value"] = [item for result in combo_input() for item in result if item]
b_combo_maker.current(0)
b_combo_maker.pack()
root.mainloop()