I am trying to make this app real quick for fun but when I try using a specific if statement, it doesn't follow through. Even though the values needed for it is present.
Here is the code for logging in and etc:
from tkinter import *
import json, threading, time
window = Tk()
window.title("MikuOS")
window.geometry('350x200')
global loggedin
loggedin = False
a = ''
if 'false' not in open('users.json', 'r').read():
lbl = Label(window, text="Welcome to MikuOS! MikuOS is in alpha.\nPlease enter a new password: ")
lbl.grid(column=0, row=0)
txt = Entry(window,width=15)
txt.grid(column=1, row=0)
def clicked():
json.dump({'users':{'password':txt.get(), 'firsttime':False}}, open('users.json', 'w'))
lbl.destroy()
txt.destroy()
btn.destroy()
btn = Button(window, text="entr", command=clicked)
btn.grid(column=2, row=0)
elif 'false' in open('users.json', 'r').read() and loggedin != True:
lbl = Label(window, text="Welcome to mikuOS!\nPlease enter your password to continue. ")
lbl.grid(column=0, row=0)
def clicked():
if txt.get() == json.load(open('users.json', 'r'))['users']['password']:
loggedin = True
lbl.destroy()
txt.destroy()
btn.destroy()
print(loggedin)
txt = Entry(window,width=15)
txt.grid(column=1, row=0)
btn = Button(window, text='enter', command=clicked)
btn.grid(column=1, row=1)
print(loggedin)
if loggedin == True:
print(loggedin)
def key_pressedo(event):
global a
a = 'o'
def olbld():
olbl.destroy()
if 'owo' in a:
a =''
olbl = Label(window, text="OwO mode activated! (it only displays this)")
olbl.grid(column=0,row=0)
olbl.after(5000, olbld)
print(a)
def key_pressedw(event):
global a
a ='w'
print(a)
window.bind("o",key_pressedo)
window.bind("w",key_pressedw)
window.mainloop()
No errors. Here is some totally extra details in order for me to add the whole code so people can actually help me because stackoverflow is just annoying when it comes to preventing people from doing that but alright I understand why anyways this should be the end of this bye bye anyways I hope you can help me/get helped by this question.
CodePudding user response:
The code is going back to loggedin = False
constantly which causes it to reset to False and not keep it all True, you can fix this by putting the loggedin = False
before the imports.