3

当我打开一个文件对话框然后将其他内容写入根目录时,我可以使用向上和向下箭头更改旋转框的值,但我无法单击并写入它。我在这里做错了什么?这是一个已知的错误?

当我不打电话filedialog.askopenfilename并手动输入路径时,它工作正常..

编辑:

当我单击组合框的下拉箭头一次时,我可以写入它?!

from tkinter import filedialog, messagebox, Spinbox, Label, Frame, StringVar, Tk, Button, ttk

colors = ["magma", "inferno", "YlOrBr", "YlOrRd", "Wistia"]

# Pfad einlesen

def readPath():
    sheetPath = filedialog.askopenfilename(title = "Choose File",filetypes = (("all files","*.*"),(".xls","*.xls"),(".xlsx","*.xlsx")))
    # sheetPath = "C:/Users/leoch/trends.xls"

class Window(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.master = master

        sensorData = readPath()

        lb = Label(root, text="Settings") #, padx=20, pady=20
        lb.pack()
        root.title("Settings")
        textStart = Label(root, text="From Row: ")
        textStart.pack()
        tvOffset = StringVar(root)
        tvOffset.set=(18)
        spinStart = Spinbox(root, from_=18, to=20, width=7, textvariable=tvOffset)
        spinStart.pack()
        labelFarben = Label(root, text="Colors")
        labelFarben.pack()
        comboFarben = ttk.Combobox(root, values=colors) 
        comboFarben.current(0)
        comboFarben.pack()

        def confirm():
            root.withdraw()
            # visualization(sensorData, rowStart, rowCount, fps, interpolation, farben)

        confirm = Button(root, text="Bestätigen", command=confirm, font=20, padx=20, pady=10, border=2, fg="green")
        confirm.pack(padx=20, pady=20)

root = Tk()
app = Window(root)
root.wm_title("Wäremstromvisualisierung")
root.mainloop()
4

1 回答 1

2

你应该focus_force()在你打电话后添加readPath()

此外,为了使ttk.Combobox只读,使用state='readonly'

from tkinter import filedialog, messagebox, Spinbox, Label, Frame, StringVar, Tk, Button, ttk

colors = ["magma", "inferno", "YlOrBr", "YlOrRd", "Wistia"]

# Pfad einlesen

def readPath():
    sheetPath = filedialog.askopenfilename(title = "Choose File",filetypes = (("all files","*.*"),(".xls","*.xls"),(".xlsx","*.xlsx")))
    # sheetPath = "C:/Users/leoch/trends.xls"

class Window(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.master = master

        sensorData = readPath()
        self.master.focus_force()
        lb = Label(root, text="Settings") #, padx=20, pady=20
        lb.pack()
        root.title("Settings")
        textStart = Label(root, text="From Row: ")
        textStart.pack()
        tvOffset = StringVar(root)
        tvOffset.set=(18)
        spinStart = Spinbox(root, from_=18, to=20, width=7, textvariable=tvOffset)
        spinStart.pack()
        labelFarben = Label(root, text="Colors")
        labelFarben.pack()
        comboFarben = ttk.Combobox(root, values=colors,state='readonly') 
        comboFarben.current(0)
        comboFarben.pack()

        def confirm():
            root.withdraw()
            # visualization(sensorData, rowStart, rowCount, fps, interpolation, farben)

        confirm_b = Button(root, text="Bestätigen", command=confirm, font=20, padx=20, pady=10, border=2, fg="green")
        confirm_b.pack(padx=20, pady=20)

root = Tk()
app = Window(root)
root.wm_title("Wäremstromvisualisierung")
root.mainloop()
于 2021-07-28T10:37:17.653 回答