Python Forum
[Tkinter] Two text files in Text widget (python 3)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Two text files in Text widget (python 3)
#2
this code:
filename =('archives/loc1.txt')
fichier = open(filename, "r")
content_generalites= fichier.read()
fichier.close()
  
T_generalites.insert(END, content_generalites)
can be simplified to:
with open(filename, "r") as fichier:
    for line in fichire:
        T_generalites.insert(END, line.strip())
I don't see a second file, but just add a similar phrase for the second file

also, if you wish to intermingle data from both files, you can use:
with open(file1, 'r') as f1, open(file2, 'r') as f2:
    ...
Reply


Messages In This Thread
RE: Two text files in Text widget (python 3) - by Larz60+ - Nov-04-2018, 09:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  update text variable on label with keypress knoxvilles_joker 5 5,564 May-31-2024, 02:09 PM
Last Post: menator01
  Button to +1 in text box everytime it's clicked martyloo 1 596 May-01-2024, 02:32 PM
Last Post: Axel_Erfurt
  Transparent window background, but not text on it muzicman0 7 3,350 Feb-02-2024, 01:28 AM
Last Post: Joically
  [Kivy] Create a function to store text fields and drop downs selection in KivyMD floxia 0 1,813 Dec-18-2022, 04:34 AM
Last Post: floxia
  [Tkinter] Updating tkinter text BliepMonster 5 6,780 Nov-28-2022, 01:42 AM
Last Post: deanhystad
  Can't change the colour of Tk button text Pilover 6 15,469 Nov-15-2022, 10:11 PM
Last Post: woooee
  [PyQt] QLineEdit Caret (Text Cursor) Transparency malonn 5 3,074 Nov-04-2022, 09:04 PM
Last Post: malonn
  [PyQt] Hover over highlighted text and open popup window DrakeSoft 2 1,724 Oct-29-2022, 04:30 PM
Last Post: DrakeSoft
  [PyQt] Determine whether text in QTableView cell is fully visible or not random_nick 0 1,081 Oct-27-2022, 09:29 PM
Last Post: random_nick
  [PyQt] [Solved]Change text color of one line in TextBrowser Extra 2 5,232 Aug-23-2022, 09:11 PM
Last Post: Extra

Forum Jump:

User Panel Messages

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