Python Forum
python file(.py) not working with my tkinter project
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python file(.py) not working with my tkinter project
#3
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.
Reply


Messages In This Thread
RE: python file(.py) not working with my tkinter project - by DeanAseraf1 - Jul-29-2019, 06:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using Tkinter inside function not working Ensaimadeta 5 5,143 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  tkinter toggle buttons not working Nu2Python 26 7,182 Jan-23-2022, 06:49 PM
Last Post: Nu2Python
  [Tkinter] remove file from current project rwahdan 2 2,332 Jul-25-2021, 09:14 AM
Last Post: Larz60+
  [Tkinter] Tkinter - I need to read file excel from GUI app to script file johnjh 0 10,759 Apr-17-2020, 08:14 PM
Last Post: johnjh
  Tkinter scaling windows conten to or with its size not working Detzi 5 4,523 Jan-12-2020, 12:42 PM
Last Post: Detzi
  [Tkinter] Mouse click event not working on multiple tkinter window evrydaywannabe 2 3,800 Dec-16-2019, 04:47 AM
Last Post: woooee
  Problem In calling a Function from another python file of project vinod2810 7 5,405 Oct-05-2019, 01:09 PM
Last Post: ichabod801
  [Tkinter] sleep(n) not working inside tkinter mainloop roger31415 2 5,226 Jul-14-2019, 06:57 PM
Last Post: wuf
  Python, Tkinter. How to search a specific file in a folder Roo 3 3,454 Feb-13-2019, 10:41 AM
Last Post: Larz60+
  tkinter - global variable not working albry 2 7,102 Jan-26-2019, 04:22 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020