我一直在創建一個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