Apr-12-2024, 06:10 PM
hello
I am a very beginner in python (2 months) and I am trying co complete a script that seems
very simple even for a beguinner , but I am giving up!
I am just willing to open a text file - the name is fixed- without using the filedialog tool .
So what is wrong in my code below
.
The error is at the end of the script .
many thanks!
--------------------------------------------------
I am a very beginner in python (2 months) and I am trying co complete a script that seems
very simple even for a beguinner , but I am giving up!
I am just willing to open a text file - the name is fixed- without using the filedialog tool .
So what is wrong in my code below
.The error is at the end of the script .
many thanks!
--------------------------------------------------
import tkinter as tk
def open():
filename = "sample1.txt"
if filename:
my_file = open(filename)
textArea.insert(tk.END, my_file.read())
elif not filename:
messagebox.showinfo("Cancel", "You clicked Cancel")
root = tk.Tk()
root.title("Text try")
text_widget = tk.Text(root, wrap=tk.WORD)
text_widget.pack(padx=20, pady=20, fill="both", expand=True)
save_button = tk.Button(root, text="lire File", command=open)
save_button.pack(pady=10)
status_label = tk.Label(root, text="", padx=20, pady=10)
status_label.pack()
root.mainloop()
[i][b]''' error message
File "C:\Users\Zapad\AppData\Local\Programs\Python\Python312\A-GARDE-MODULES-SOURCE\zzoihj.py", line 6, in open
my_file = open(filename)
^^^^^^^^^^^^^^
TypeError: open() takes 0 positional arguments but 1 was given '''[/b]
[/i]
