Ask coding questions

← Back to all posts
Search box
adeen11 (2)

Hi guys...I’m new to GUIs on python!!!! 😩
I’ve got a question, I’m basically opening a .txt file and searching through the lines for a string; this string is found after a few 100 lines.
My aim is basically to have a GUI that opens the .txt (using a GUI dialog box) then have another dialog that “searches” through this file (for the given string)...and exports the the lines from one instance to the next...in a new .txt file!
I’d appreciate your help!!!

Comments
hotnewtop
Dart (1199)

In python you can write to a txt file like this:

file = open('textfile.txt', 'w')
file.write("content")
file.close()
adeen11 (2)

@Zexogon Thanks pal...but would you also know how to invoke a dialog which prompts the user for a 'String Search' which is then used to search through a .txt and have that extracted on a new .txt?

Dart (1199)

@adeen11 You can do a with open in read mode to look for somthing in a txt file

adeen11 (2)

And btw; this code works when used on PyCharm...not repl unfortunately 😪