python file(.py) not working with my tkinter project - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: python file(.py) not working with my tkinter project (/thread-20144.html) |
python file(.py) not working with my tkinter project - DeanAseraf1 - Jul-29-2019 Hey everyone, I'm trying to run my project by opening the .py project file and it doesn't work for some reason. If I'm trying to run the code in Pycharm it works perfectly fine but when I'm trying to open it from the .py file it start(you see the 'CMD' (black window) pop up and then close, the Tkinter window dose not show at all) let me just say that I'm using the root.mainloop() function of course(in Pycharm it works fine) and my other Tkinter projects the .py file works fine too. what can cause this kind of problem? thanks RE: python file(.py) not working with my tkinter project - metulburr - Jul-29-2019 It would be helpful to know more information RE: python file(.py) not working with my tkinter project - DeanAseraf1 - Jul-29-2019 This is my code: from tkinter import * from tkinter import ttk import pyperclip import ast def fst_window(): password_label = Label(root, text="Password:") password_label.grid(row=0, column=0) password_holder = StringVar() password_entry = Entry(root, textvariable=password_holder, show="*") password_entry.grid(row=0, column=1) enter1_button = Button(root, text="Enter", command=lambda: pass_checker(password_holder)) enter1_button.grid(row=0, column=3) root.bind("<Return>", lambda event: pass_checker(password_holder)) def start_prog(): root.destroy() form = Tk() form.title("Passwords") form.geometry("275x300+700+400") tab_parent = ttk.Notebook(form) tab1 = ttk.Frame(tab_parent) website_label = Label(tab1, text="Website:") website_label.grid(row=0, column=0) website_holder = StringVar() website_entry = Entry(tab1, textvariable=website_holder) website_entry.grid(row=0, column=1) passwords_label = Label(tab1, text="Password:") passwords_label.grid(row=1, column=0) passwords_holder = StringVar() passwords_entry = Entry(tab1, textvariable=passwords_holder, show="*") passwords_entry.grid(row=1, column=1) enter2_button = Button(tab1, text="Enter", command=lambda: viewer(website_holder, passwords_holder)) enter2_button.grid(row=2, columnspan=2) form.bind("<Return>", lambda event: viewer(website_holder, passwords_holder)) tab2 = ttk.Frame(tab_parent) new_webpas = [] def viewer(web, pas): try: website = web.get() password = pas.get() if website not in new_webpas: new_webpas.append(password) new_webpas.append(website) fst_password = Label(tab2, text=str(website) + '==>' + str(password)) fst_password.grid(column=0) fst_paste_button = Button(tab2, text="Copy", command=lambda: copy(str(password))) fst_paste_button.grid(column=1) fst_del_button = Button(tab2, text="Delete") fst_del_button.grid(column=2) website_entry.delete(0, END) passwords_entry.delete(0, END) else: print("You already have this website in the list") except AttributeError: fst_password = Label(tab2, text=str(web) + '==>' + str(pas)) fst_password.grid(column=0) fst_paste_button = Button(tab2, text="Copy", command=lambda: copy(str(pas))) fst_paste_button.grid(column=1) fst_del_button = Button(tab2, text="Delete", command=lambda: delete(fst_del_button, fst_paste_button, fst_password, web, pas)) fst_del_button.grid(column=2) def delete(delete, pst, password, website, pas): delete.grid_remove() pst.grid_remove() password.grid_remove() new_webpas.remove(pas) new_webpas.remove(website) def copy(password): pyperclip.copy(password) def saver(): lstfile_wr = open("C:\\Users\\Dean\\Desktop\\Passwords.txt", "w+") lstfile_wr.write(str(new_webpas)) lstfile_wr.close() def updater(): lstfile_r = open("C:\\Users\\Dean\\Desktop\\Passwords.txt", "r") readtext = lstfile_r.read() lstfile_r.close() try: nano = ast.literal_eval(readtext) except SyntaxError: nano = "" print("Your file is empty") index = 1 for item in nano: if index % 2 != 0: password = item if password not in new_webpas: new_webpas.append(password) index += 1 else: print("You already have this password in the list") else: website = item if website not in new_webpas: new_webpas.append(website) viewer(website, password) index += 1 else: print("You already have this website in the list") tab3 = ttk.Frame(tab_parent) save_button = Button(tab3, text="Save", command=saver) save_button.pack() load_button = Button(tab3, text="Load", command=updater) load_button.pack() tab_parent.add(tab1, text="Enter Passwords") tab_parent.add(tab2, text="Copy Passwords") tab_parent.add(tab3, text="Load and Save") tab_parent.pack(expand=0, fill='both') updater() form.mainloop() def pass_checker(gvn_password): cur_pass = "44" password = gvn_password.get() if password == cur_pass: start_prog() else: print("Password Incorrect!") root = Tk() root.title("Passwords") root.geometry('225x30+750+480') fst_window() root.mainloop()Sorry it's so messy but I'm new to coding. My problem is that when I run the project in Pycharm it works fine, but when I'm trying to run it by opening the .py file it start normally and close before the Tkinter window even appeared. RE: python file(.py) not working with my tkinter project - metulburr - Jul-29-2019 I more on the lines meant these Quote: RE: python file(.py) not working with my tkinter project - DeanAseraf1 - Jul-29-2019
RE: python file(.py) not working with my tkinter project - Yoriz - Jul-29-2019 Try the following code in a separate .py file. import sys print(sys.version) input('press enter to continue')run it in the same way and see what output you get in the black window. RE: python file(.py) not working with my tkinter project - DeanAseraf1 - Jul-30-2019 Quote:3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] This is what got written in the black window. This program is the only program I wrote that doesn't work this way, so I don't think that it's a problem with the python or somthing. RE: python file(.py) not working with my tkinter project - Yoriz - Jul-30-2019 As that is working and seems to be the same version of python, the input stops the cmd window closing until you press enter. Add input('1: press enter to continue') at various places in the tkinter code, changing the number each time.Hopefully this will keep the cmd window open to see an error that's happened and pinpoint where it is not working. RE: python file(.py) not working with my tkinter project - DeanAseraf1 - Jul-30-2019 I've tried to add the input function and it still doesn't show anything on the cmd window and then closes automatically. RE: python file(.py) not working with my tkinter project - ifigazsi - Mar-22-2020 (Jul-30-2019, 12:55 PM)DeanAseraf1 Wrote: I've tried to add the input function and it still doesn't show anything on the cmd window and then closes automatically. I'm a newbie as well, same problem. I pip installed all of my modules, it seems working now. :) In your case: pip install pyperclip pip install AST Best regards, ifigazsi |