【发布时间】:2019-10-05 00:22:38
【问题描述】:
我正在尝试为某些设备创建故障排除程序,有一个输入框使用您的关键字转到正确的框架,它工作正常,但我需要一些帮助才能从 csv 文件中读取每个单独的步骤具体问题。为此,我制作了一个读取 csv 文件中第一步的按钮,但是,我想制作另一个名为“Next Step”的按钮,每次单击时都会显示 csv 文件中的下一步。我也想知道我怎样才能摆脱“第一步”按钮,这样就不会混淆,这样才有意义。我已经尝试分配一个等于 True 的变量并进行了一个 while 循环来实现它,因此该按钮仅在变量设置为 true 时才显示,这根本不起作用。任何关于如何使这项工作的想法,一切都非常感谢。
这是我的代码
class wetDevice(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="How to fix a wet phone", fg="purple", font=controller.title_fontT)
label.pack(side="top", fill="x", pady=10)
def stepOne():
with open("Wet Device.csv", "r") as f:
csvreader = csv.reader(f, delimiter=",")
for row in csvreader:
if "1" in row[0]:
test = str(row[1])
stepOneL = tk.Label(self, text=test)
stepOneL.place(x = 10, y = 70, width = 500, height = 20)
#def nextStep():
stepOneB = tk.Button(self, text="First Step",
command=lambda: stepOne())
stepOneB.place(x = 230, y = 130, width = 60, height = 20)
mButton = tk.Button(self, text="Go to the Main Troubleshoot Menu",
command=lambda: controller.show_frame("MainTMenu"))
mButton.place(x = 285, y = 210, width = 200, height = 25)
csv 文件采用这种格式(只需 5 个步骤):
Step, Instructions
1, instruction
2, instruction
3, instruction
4, instruction
5, instruction
如果你们能帮助我打开同一项目文件夹中另一个文件夹中的 csv 文件,我也将不胜感激。
非常感谢任何帮助
【问题讨论】:
-
你的问题不是很清楚,而且你给出的代码不起作用,我已经编辑了它,所以它会起作用,但它似乎仍然不能像你解释的那样起作用做。请确保您提供可行的代码。
标签: python python-3.x csv tkinter