打开文件对话框后无法写入 tkinter spinbox
Can't write into tkinter spinbox after filedialog was opened
当我打开文件对话框然后将其他内容写入根目录时,我可以使用向上和向下箭头更改旋转框的值,但我不能单击并写入它。我在这里做错了什么?这是已知错误吗?
当我不调用 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()
您应该在调用 readPath()
之后添加 focus_force()
此外,为了使 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()
当我打开文件对话框然后将其他内容写入根目录时,我可以使用向上和向下箭头更改旋转框的值,但我不能单击并写入它。我在这里做错了什么?这是已知错误吗?
当我不调用 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()
您应该在调用 readPath()
focus_force()
此外,为了使 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()