Python: How to make Next button read diffrent files. [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'am going to make a window with Next button, a Text Widget and Label widget. I want when I klick on Next button will read adiffrent files on Text widget, i mean first click on Nexst will read file_1 in Text widget, and secound click will read file_2, and so on. so can anyone help me, thanks

Shelf might do it. Try opening the file in shelf, reading it, printing it, then closing it. When the button is hit a variable is incriminated. This variable points to an index in an array which holds the file names. It would then pass the file path to the function like this:
import shelve
I = 0
Paths = array containing file paths
FUNCTION file (path):
This function opens reads prints and closes the - file at path
WHILE True:
This loop calls the function with args paths[i]
I++
BTW THAT EAS NOT MEANT TO BE PYTHON CODE BUT JUST A REPRESENTATION
P.S if I have got the wrong end of the stick pls tell me and I will change my awnser

Related

I am stuck at TypeError in tkinter. How to fix it? Please guide me [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I was making a python reader project and wanted to make a python reader (In which the python will read what you wrote in the entry) it works fine but when I write something in the entry it gives me a type error:
and my code:
The problem is somewhere after clicking a read button before that it works just like I want but after clicking the button the problem happens.
Your function funcation is defined to be given str in line 18
def funcation(str):
but you're calling the function without any arguments from reader_btn in line 38: funcation
what you want to do is passing the text variable containing the string like
command=lambda: funcation(text)
from your reader_btn
EDIT:
or probably better read the value of your entry when the button is pressed:
command=lambda: funcation(text_place.get())
thanks to quamrana for pointing that out

How can I display a file's text into a desktop line by line using Tkinter module? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
community!
I'm writing my own screensaver using Python 2.7 and Tkinter module. Almost done, but stuck with the following problem:
I have a long-long file with, say, .py extension and a lot of code in it, which I want to display line by line into the GUI desktop, using Tkinter module. I managed to do exactly what I want for console using file.readlines(), but I cannot find out how to do that in GUI.
I have used a tk.Text widget and got the file in full, while I want the lines appear one after another, like when you use f.readlines().
Is there any method to make the tk.Text do that?
You can do by making a Text box :
try:
from tkinter import *
except:
from Tkinter import *
root=Tk()
t=Text(root,height=25,width=100,wrap=WORD)
t.pack()
f=open('a','r')
r=f.readlines()
f.close()
time=1000 # in ms
def f():
global r
t.insert(END,r[0])
r=r[1:]
t.after(time,f)
f()
mainloop()

How to change data in notepad using python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Ok so I want to make a simple game where it's essential for the game to save. I wish to store all the data in notepad. However how do I pull notepad into python. I have tried saving notepad into the same folder where my .py file is. Then in the program im not sure what to do. Im just very confused on how to do this. I do know how to program in python, but how do I pull data out of notepad into python.
Also I wish to know how would I change the inside of the notepad file. Let's just say it has a couple of variables with certain numbers. I want to change those in game.
Thank you for any answers. :)
You stored your data in text file not in notepad. Notepad is an application to edit and read the data inside the text file.
Suppose you stored tha data in a text file (whose name is file.txt) using notepad. Now you want to read the data inside text file from your python code. You can read it directly as :
Python code :
file_pointer = open("file.txt", "r");
array = file_pointer.readlines()
print(array[0])
print(array[1])
print(array[2])
print(array[3])
file.txt
25
554
51
4147

Open a text file window using Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to write a text based game in python that uses a lexicon(A list of accepted inputs and their grammatical parts). Say I have a file lexicon.txt that contains a list of accepted terms for each room, such as attack(verb), dragon(noun), and up(direction). I know that I could print the contents of that file to my program with lexicon.read(), but then after the user has played enough that he can't see that part anymore, he might type an unrecognized word. I would rather have the lexicon constantly opened in another window where you could have easy access to it at any time. Is there any way to make my python file import lexicon.txt and open a window of notepad to display the contents?
There are many ways to do this.
This opens the file with the default application:
import os
os.startfile(filename)
To open the file explicitly with notepad use this:
import os
os.system("notepad.exe file.txt")

Looking for a way to identify and replace Python variables in a script [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a dictionary of variablenames and I want those to be the variablenames in another script. So I probably need to identify all variables in a Python script and then somehow replace those with the desired ones from the dictionary. Yet I cannot figure out what might be the most elegant way to do that.
Do I have to paste the one script as a string to the other script that does the replacement? Any tips? Thanks
Edit: The actual question is not to request a complete solution rather than asking whether there is a possibility to identify which word in a script is actually a variable. Is it possible to find these eg compare them to PythonBuiltIn variables?!
Python can read python. So write a script with that dictionary that looks at your first script and uses regex to replace the correct symbols. Make the file you want to modify an in file and read it, edit it, and write it back to the .py file line by line.
heres doc on file I/O in python just in case you need it:
http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files
To assign global variables using a dictionary from another module:
from other_module import desired_dictionary
if __name__=="__main__":
import this_module
for name, value in desired_dictionary.items():
setattr(this_module, name, value)
I now chose to simply identify variables as the last word coming before a "=" character in a script. (Does that make sense?)
I use
line.split("=")[0].split(" ")[-1]
to identify those words after opening the script as proposed by NKamrath with
f = open('replaceme.py')
f.readlines()
Thanks a lot for the help so far!

Categories