29 Answers
New Answerfrom tkinter import * root=Tk() f=open("main.txt","w+") replace=f.replace("main.txt","name.txt") f.close() name=StringVar() nam=Label(text="Name of customer") txtnam=Entry(textvariable=name) root.mainloop()
1/1/2020 1:41:22 PM
Sushmita Khadka29 Answers
New Answerimport shutil shutil.move('main.txt', 'name.txt') there are a couple of ways on how this can be done
I created 2 programs in same dir: helloworldprogram.py: print("hi") renamer.py: import os os.rename("helloworldprogram.py", "bananapeel.py") And running renamer.py successfully changed "helloworldprogram.py" name to "bananapeel.py".
Import os os.rename("main.txt","name.txt") ☝️☝️ this is code that I have but it will creat name.txt but I want the name that is store inside name
#Does this work? import os from tkinter import * root=Tk() f=open("main.txt","w+") replace=f.replace("main.txt","name.txt") f.close() name=StringVar() nam=Label(text="Name of customer") txtnam=Entry(textvariable=name) os.rename("main.txt", txtnam + ".txt") root.mainloop()
def rename(): os.rename("main.txt", txtnam.get()) Because the tkinter uses mainloop, you would need any tkinter widget (such as function) to call this function.
Should I be able to type something if I took the file openings away?: from tkinter import * root=Tk() name=StringVar() nam=Label(text="Name of customer") txtnam=Entry(textvariable=name) root.mainloop()
from tkinter import * root = Tk() name = StringVar() nam = Label(text="Name of customer") nam.pack() txtnam = Entry(textvariable=name) txtnam.pack() root.mainloop()
Sushmita Khadka I don't know what's grid, but I made a code that worked, it changed file main.txt name to text I typed + ".txt"
Seb TheS Thank u so much your idea I mean your code os.rename("main.txt" , txtnam+".txt") works I change a little bit...... but because of u I complete my project😊😊 Thank u
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message