I have made the changes that people have suggested from my previous question. I want to try and make it even tidier if possible. What can I change to make it more optimized? My import
s are quite messy and I am not sure what ones I actually need, so if you can help with that, please do.
#Imports
import tkinter
from tkinter import *
from tkinter.filedialog import askopenfilename
from tkinter.filedialog import asksaveasfilename
from tkinter.messagebox import showerror
from tkinter import filedialog
import sys
class MyFileManager(object):
def __init__(self, filename='', save_filename=''):
self.filename = filename
self.save_filename = save_filename
def save_users_list(self, list_name):
with open(self.filename, 'r') as file:
users_list = [line.strip() for line in file.readlines()]
with open(self.save_filename, 'w') as file:
file.write('{} = {}'.format(list_name, str(users_list)))
def get_filename(self):
self.filename = askopenfilename(filetypes=(("Text files", "*.txt"),
("All files", "*.*")))
def get_save_file(self):
self.save_filename = asksaveasfilename(filetypes=(("Text files", "*.txt"),
("All files", "*.*")))
manager = MyFileManager()
#Window
window = tkinter.Tk()
window.title("Python List Maker")
window.geometry("300x170")
#Label
file_select_label = tkinter.Label(window, text="Please select your file:")
file_select_label.pack()
#Button
filename_button = tkinter.Button(window, text="Browse", command=manager.get_filename)
filename_button.pack()
#List Name
list_name_label = tkinter.Label(window,text="Please enter what you want to call the list:")
list_name_label.pack()
list_name = Entry(window)
list_name.pack()
#Save List
save_list_label = tkinter.Label(window,text="Please select where you want to save the list:")
save_list_label.pack()
save_filename_button = tkinter.Button(window, text="Browse", command=manager.get_save_file)
save_filename_button.pack()
#Go
go_button = tkinter.Button(window, text="Go!", command=lambda: manager.save_users_list(
list_name.get()))
go_button.pack()
#Main Loop
window.mainloop()