Python Forum
very newbie problem on text file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
very newbie problem on text file
#1
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 Huh .

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]
Reply
#2
You cannot define a function named "open". It replaces the "open" you try to use here:
my_file = open(filename)
Reply
#3
hi deanhystad
thanks ! your post did the job!
tks & good evening
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,148 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,724 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Converted Pipe Delimited text file to CSV file atomxkai 4 7,035 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  Newbie first problem cima_hurdle 8 3,481 Feb-09-2022, 10:02 PM
Last Post: cima_hurdle
  [split] How to convert the CSV text file into a txt file Pinto94 5 3,397 Dec-23-2020, 08:04 AM
Last Post: ndc85430
  Saving text file with a click: valueerror i/o operation on closed file vizier87 5 4,449 Nov-16-2020, 07:56 AM
Last Post: Gribouillis
  Newbie Start with Text or Table? abrogard 5 2,555 Oct-18-2020, 12:47 PM
Last Post: jefsummers
  saving data from text file to CSV file in python having delimiter as space K11 1 2,422 Sep-11-2020, 06:28 AM
Last Post: bowlofred
  Web Form to Python Script to Text File to zip file to web wfsteadman 1 2,157 Aug-09-2020, 02:12 PM
Last Post: snippsat
  Convert Excel file to Text file marvel_plato 6 19,804 Jul-17-2020, 01:45 PM
Last Post: marvel_plato

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020