我一直在创建一个gui使用tkinter。tkinter在Python中的输入输出3
我想从用户接收一个文件名作为输入,打开该文件并显示与由函数生成的文本的消息框。
下面是代码,有人可以解释为什么这是行不通的?
import tkinter as tk
import csv
import tkinter.simpledialog
import tkinter.messagebox
from tkinter import ttk
file=tkinter.simpledialog.askstring("File: ","Enter your file name")
with open(file, 'r') as f: #this line reads the file
reader = csv.reader(f, delimiter=',')
output=values
def values(): #And this is the function
print("Some text")#which should return whatever info is inside 'print' function
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
button = ttk.Button(self, text="Submit", #I prefer using the button but any other way will do
command=tkmessagebox.showinfo("Results",output))
button.pack()
我得到“name”tksimpledialog'未定义“错误。
您描述了预期的结果,但错误是什么? – dparoli
编辑该问题。 – Yar