_tkinter.TclError: bad window path name ".!frame2" - python

I am making a project which is supposed to close the first window and open a new one, but I get this error in line 101 which says "d2.pack()" in the roll() function. I want to make it so whenever you press the "roll" button, the old frame with the old roll dissapears and a new one will appear in the exact same place with the new roll, before it would just appear underneath the old roll so I tried to do something to make it work, but nothing has worked yet. I have tried quite some things but nothing works. As I am quite new to coding, any help would be appreciated.
from csv import excel_tab
import sqlite3
from turtle import width
from argon2 import PasswordHasher
from tkinter import *
from tkinter import ttk
import atexit
global active_user
def raise_frame(frame):
frame.tkraise()
ph = PasswordHasher()
root = Tk()
root.geometry("750x500")
f1 = Frame(root)
f2 = Frame(root)
f3 = Frame(root)
for frame in (f1, f2, f3):
frame.pack()
con = sqlite3.connect("nope you're not getting this")
cur = con.cursor()
def slots():
return
def createAcc():
password = newPass.get()
usernameNew = newUser.get()
hashed_password = ph.hash(password)
cur.execute("INSERT INTO thing (user, money, password, sessionactive) VALUES (?,?,?,?)", (usernameNew, 10000, hashed_password, 0))
con.commit()
main()
def login():
global entryUsername
global entryPass
label = Label(f2, text="Enter username and password", font=("Courier 22 bold"))
label.pack(padx=0, pady=10)
entryUsername = Entry(f2, width= 40)
entryUsername.focus_set()
entryUsername.pack(padx=0, pady=10)
entryPass = Entry(f2, width= 40)
entryPass.focus_set()
entryPass.pack()
ttk.Button(f2, text= "Enter",width= 20, command=loginCheck).pack(pady=20)
raise_frame(f2)
def create():
global newUser
global newPass
label = Label(f3, text="Create username and password", font=("Courier 22 bold"))
label.pack(padx=0, pady=10)
newUser = Entry(f3, width= 40)
newUser.focus_set()
newUser.pack(padx=0, pady=10)
newPass = Entry(f3, width= 40)
newPass.focus_set()
newPass.pack()
ttk.Button(f3, text= "Enter",width= 20, command=createAcc).pack(pady=20)
raise_frame(f3)
def loginCheck():
global username
global active_user
i = 0
password = entryPass.get()
username = entryUsername.get()
cur.execute("SELECT * FROM thing")
data = cur.fetchall()
while i < len(data):
if data[i][0] == username and ph.verify(data[i][2], password) == True:
active_user = username
main()
else:
i += 1
print("Invalid username or password, please try again")
def roll():
global d2
new_frame = d2
if d2 is not None:
d2.destroy()
d2 = new_frame
d2.pack() #here's the error
Label(d2, text="test", font=("Courier 22 bold")).pack()
def main():
global root
global root2
global d1
global d2
f1.destroy()
root2 = Tk()
d1 = Frame(root2)
d2 = Frame(root2)
for frame in (d1, d2):
frame.pack()
root2.geometry("750x500")
Label(root2, text="Press roll to roll the slots", font=("Courier 22 bold")).pack(pady=20)
ttk.Button(d1, text="Roll", width=20, command=roll).pack(pady=40)
root2.mainloop()
def mainScreen():
label = Label(f1, text="Welcome to epic gambling thing!", font=("Courier 22 bold"))
label.pack(padx=0, pady=10)
ttk.Button(f1, text= "Login",width= 20, command=login).pack(pady=20)
raise_frame(f1)
ttk.Button(f1, text= "Create Account",width= 20, command=create).pack(pady=20)
mainScreen()
root.mainloop()

Related

How can i get the value from the entry and inject into the init function parameter?

Here's the code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
import sys
class TwitterBot:
def __init__(self, username, password):
self.username = username
self.password = password
entry_user = tk.Entry(lower_frame, bg="white", fg='black', bd=0)
#entry_user.insert(0, "Username")
#entry_user.bind("<Button-1>", del_value_user)
entry_user.pack(expand = "yes")
entry_pass = tk.Entry(lower_frame, bg="white", fg='black', bd=0)
#entry_pass.insert(0, "Password")
#entry_pass.bind("<Button-1>", del_value_pass)
entry_pass.pack(expand = "yes")
sasha = TwitterBot(entry_user.get(), entry_pass.get())
The entry never send the values I typed in into sasha = TwitterBot(entry, entry2)
Meaning I want that inside tkinter interface, I type in two entries that supposed to be username and password and when I execute the function those values get injected. I think the problem is that self.username and self.password are defined inside of the __init__ and so if those entries stay empty at the launch so i cant get them to inject. cause I can print my entry.get() values. I just cant make them replace the two first parameters of my __init__ function. Does anybody knows how to help?
Try this:
import tkinter as tk
class TwitterBot:
def __init__(self, username, password):
print("Username =", username, " Password =", password)
self.username = username
self.password = password
def create_bot(event=None):
sasha = TwitterBot(entry_user.get(), entry_pass.get())
print("started bot")
root = tk.Tk()
entry_user = tk.Entry(root, bg="white", fg='black', bd=0)
#entry_user.insert(0, "Username")
#entry_user.bind("<Button-1>", del_value_user)
entry_user.pack(expand=True)
# Log in if the user presses the Enter key:
entry_user.bind("<Return>", create_bot)
entry_pass = tk.Entry(root, bg="white", fg='black', bd=0)
#entry_pass.insert(0, "Password")
#entry_pass.bind("<Button-1>", del_value_pass)
entry_pass.pack(expand=True)
# Log in if the user presses the Enter key:
entry_pass.bind("<Return>", create_bot)
button = tk.Button(root, text="Log in", command=create_bot)
button.pack()
root.mainloop()
Your code wasn't working because as soon as your code created the entries it tried to get the data out of them (which obviously is an empty string) and created the TwitterBot object. To make it work you have to give the user time to enter their details in the entries by adding a button/binding to the user pressing the Enter key.
I created a button and placed it at the bottom of the window. When you click the button it calls create_bot which creates the TwitterBot object.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
import sys
import tkinter as tk
from tkinter import *
from tkmacosx import Button as button
class TwitterBot:
def __init__(self, username, password):
print("Username =", username, " Password =", password)
self.username = username
self.password = password
def open_br(self):
self.bot = webdriver.Firefox()
def end_br(self):
self.bot.quit()
def login(self):
bot = self.bot
bot.get("http://twitter.com/login/")
time.sleep(3)
email = bot.find_element_by_name("session[username_or_email]")
password = bot.find_element_by_name("session[password]")
email.clear()
password.clear()
email.send_keys(self.username)
password.send_keys(self.password)
password.send_keys(Keys.RETURN)
time.sleep(3)
def like_tweet(self, hashtag):
bot = self.bot
bot.get('https://twitter.com/search?q='+hashtag+'&src=typed_query')
time.sleep(3)
for i in range(1,8):
bot.execute_script('window.scrollTo(0,document.body.scrollHeight)')
time.sleep(2)
tweets = bot.find_elements_by_class_name('tweet')
tweetLinks = [i.get_attribute('href') for i in bot.find_elements_by_xpath("//a[#dir='auto']")]
filteredTweet = list(filter(lambda x: 'status' in x,tweetLinks))
print(filteredTweet)
for link in filteredTweet:
bot.get(link)
time.sleep(5)
if drop2_var.get() == "Retweet":
try:
bot.find_element_by_xpath("//div[#data-testid='retweet']").click()
bot.find_element_by_xpath("//div[#data-testid='retweetConfirm']").click()
time.sleep(3)
except Exception as ex:
time.sleep(10)
elif drop2_var.get() == "Likes":
bot.find_element_by_xpath("//div[#data-testid='like']").click()
time.sleep(3)
# def create_bot(event=None):
# sasha = TwitterBot(entry_user.get(), entry_pass.get())
# print("started bot")
sasha = TwitterBot("", "")
root = tk.Tk()
HEIGHT = 800
WIDTH = 400
#FUNCTIONS CLEARING ENTRY
def del_value(event): # note that you must include the event as an arg, even if you don't use it.
entry.delete(0, "end")
return None
def del_value_user(event): # note that you must include the event as an arg, even if you don't use it.
entry_user.delete(0, "end")
return None
def del_value_pass(event): # note that you must include the event as an arg, even if you don't use it.
entry_pass.delete(0, "end")
return None
def ex():
root.quit()
#PROGRAM SETTINGS
root.title("Social Bot")
root.minsize(400, 800)
#root.iconbitmap("/Users/sashakharoubi/Desktop/BOOTCAMP/Week 9/Day 2/image/logo.ico")
root.config(background="#66b3ff")
canvas = tk.Canvas(root, height= HEIGHT, width = WIDTH, bd=0, highlightthickness = 0)
canvas.pack()
# background_image = tk.PhotoImage(file = 'blue.png')
# background_label = tk.Label(root, image =background_image)
# background_label.place(x=0, y=0, relwidth=1, relheight=1)
#MAINFRAME
frame = tk.Frame(root, bg="#222f3e")
frame.place(relx = 0, rely = 0, relwidth = 1, relheight = 1)
#SUBPART FRAME
lower_frame = tk.Frame(root, bg="#E9E9E9", bd=0, highlightthickness = 0, relief="sunken")
#DROPDOWN MENU OPTIONS
OPTIONS = [
"Twitter",
"Instagram(not working)"
]
OPTIONS2 = [
"Likes",
"Retweet"
]
entry_txt = tk.Label(lower_frame, text="Welcome to Social Bot\n\nChoose an action to execute", font=("Montserrat", 15), bg="#E9E9E9", fg="black")
entry_txt.pack(expand = "yes")
#DROPDOWN MENU
drop_var = StringVar(lower_frame)
drop_var.set(OPTIONS[0])
drop2_var = StringVar(lower_frame)
drop2_var.set(OPTIONS2[0])
drop = OptionMenu(lower_frame, drop_var, *OPTIONS)
drop.config(fg="black")
drop.pack()
drop2 = OptionMenu(lower_frame, drop2_var, *OPTIONS2)
drop2.config(fg="black")
drop2.pack()
#ENTRIES
entry = tk.Entry(lower_frame, bg="white", fg='black', bd=0)
entry.insert(0, "-->Topic to like or retweet")
entry.bind("<Button-1>", del_value)
entry.pack(expand = "yes")
entry_user = tk.Entry(lower_frame, bg="white", fg='black', bd=0)
entry_user.insert(0, "----Type Your Username---")
entry_user.bind("<Button-1>", del_value_user)
entry_user.pack(expand = "yes")
#entry_user.bind("<Return>", create_bot)
entry_pass = tk.Entry(lower_frame, bg="white", fg='black', bd=0)
entry_pass.insert(0, "----Type Your Password---")
entry_pass.bind("<Button-1>", del_value_pass)
entry_pass.pack(expand = "yes")
#entry_pass.bind("<Return>", create_bot)
#BUTTONS
button_confirm = button(lower_frame, text="Confirm", bg="white", fg="black")
button_confirm.pack(pady=25, side = 'top')
button_open = button(lower_frame, text="Open Browser", bg="white", fg="black", command= sasha.open_br)
button_open.pack(pady=25, side = 'top')
button_log = button(lower_frame, text="LOG IN", bg='#54a0ff', fg="white", command =sasha.login, bd=0, highlightthickness = 0)
button_log.pack(pady=25, side = 'left')
button_launch = button(lower_frame, text="START", bg='#1dd1a1', fg="white", relief="flat", command = lambda: sasha.like_tweet(entry.get()), bd=0, highlightthickness = 0)
button_launch.pack(pady=25, side = 'right')
button_stop = button(lower_frame, text="STOP", bg="#ff6b6b", fg="white", command= sasha.end_br)
button_stop.pack(pady=25, side = 'bottom')
button_exit = button(lower_frame, text="Exit", bg ="white", fg="black", command= ex)
button_exit.pack(side = 'bottom')
lower_frame.place(relx = 0.1, rely = 0.1, relwidth=0.8, relheight=0.8)
#TITLE
label = tk.Label(frame, text="S O C I A L B O T", font=("Montserrat", 25), bg="white", fg="#222f3e")
label.pack(side="top", fill ="both")
root.mainloop()
v1 = browser.find_element_by_xpath("").text
try put .text at last of your code
then you can print or use v1 as a value

Python text box

I am trying to take input name, email and password from user and print it in screen. But the variable is took is showing none every time. Can anyone solve my problem?
import tkinter as tk
import tkinter.font as f
r = tk.Tk()
name=''
email=''
password=''
def Print():
print("Name is",name)
print("Email is",email)
print("Password is",password)
f=tk.Frame(r,height=600,width=900)
f.pack()
name = tk.Label(f, text = "Name").place(x = 30,y = 50)
email = tk.Label(f, text = "Email").place(x = 30, y = 90)
password = tk.Label(f, text = "Password").place(x = 30, y = 130)
sbmitbtn = tk.Button(f, text = "Submit",activebackground = "pink", activeforeground = "blue",command=lambda:[Print(),f.destroy()]).place(x = 30, y = 170)
e1 = tk.Entry(f,textvariable=name).place(x = 80, y = 50)
e2 = tk.Entry(f,textvariable=email).place(x = 80, y = 90)
e3 = tk.Entry(f,textvariable=password).place(x = 95, y = 130)
r.mainloop()
you can use StringVar to get the string. the textvariable in your Label needs to be a Tkinter variable, quote:
"
textvariable= Associates a Tkinter variable (usually a StringVar) to
the contents of the entry field. (textVariable/Variable)
you can read more here
import tkinter as tk
import tkinter.font as f
r = tk.Tk()
name = tk.StringVar()
email = tk.StringVar()
password = tk.StringVar()
def Print():
print("Name is", name.get())
print("Email is", email.get())
print("Password is", password.get())
f = tk.Frame(r, height=600, width=900)
f.pack()
tk.Label(f, text="Name").place(x=30, y=50)
tk.Label(f, text="Email").place(x=30, y=90)
tk.Label(f, text="Password").place(x=30, y=130)
sbmitbtn = tk.Button(f, text="Submit", activebackground="pink", activeforeground="blue",
command=lambda: [Print(), f.destroy()]).place(x=30, y=170)
e1 = tk.Entry(f, textvariable=name).place(x=80, y=50)
e2 = tk.Entry(f, textvariable=email).place(x=80, y=90)
e3 = tk.Entry(f, textvariable=password).place(x=95, y=130)
r.mainloop()

Change global variable to value in entry field

How can I change a global variable to a value inputted by a user in an entry field?
card_no = 0
def cardget():
global card_no
card_no = e1.get()
print(card_no)
def menu():
global card_no
root = Tk()
e1 = Entry(root).pack()
Label(root, text= "Enter card number").pack(anchor= NW)
Button(root, text= "Confirm card", command=cardget).pack(anchor= NW)
menu()
Don't use global variables. Tkinter apps work much better with OOP.
import tkinter as tk
class App:
def __init__(self, parent):
self.e1 = tk.Entry(parent)
self.e1.pack()
self.l = tk.Label(root, text="Enter card number")
self.l.pack(anchor=tk.NW)
self.b = tk.Button(root, text="Confirm card", command=self.cardget)
self.b.pack(anchor=tk.NW)
self.card_no = 0
def cardget(self):
self.card_no = int(self.e1.get()) # add validation if you want
print(self.card_no)
root = tk.Tk()
app = App(root)
root.mainloop()

Python tkinter xlsxwriter trying to export user input to excel file

from tkinter import *
import sys,math,random,datetime,os,time
import tkinter.messagebox
from tkinter import filedialog
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import showerror
from time import gmtime, strftime
import xlsxwriter
export = "Excel"
current_time = strftime("%m-%d-%Y %H:%M", gmtime())
root = Tk()
e1 = Entry()
e1.insert(10, "First Name")
e2 = Entry()
e2.insert(10, "Last Name")
Here is where I am trying to format variable to become string.
fullname = "%s %s" % (e1, e2)
title = ["Titan Tech", "Caleb Fahlgren made this!", "Python is life!", "FIRST Robotics!","Doesn't this make your life easier?"]
title = (random.choice(title))
root.title(title)
root.geometry("640x600")
#Submit Button
def Submit():
submit = tkinter.messagebox.askquestion("Submit Entry", "Are you sure you want to submit?")
if submit == "yes":
Xlsx program.
workbook = xlsxwriter.Workbook('TitanTechSummary.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': 1})
worksheet.write('A1', 'Name:',bold)
This is where I am trying to write the players input for name. Or the tkinter Entry(). But I keep getting like a weird decimal number when I look at the excel document. I keep getting this in the B1 field '.140041879004720 .140041884602944'
worksheet.write_string('B1',fullname, bold)
worksheet.write('C1', 'Date:',bold)
I also want to do the same thing with the date.
worksheet.write('D1', 'Date')
workbook.close()
userconfirm = tkinter.messagebox.showinfo("Save","Your entry has been saved to an " + export + " document!")
def keypress(event):
if event.keysym == 'Escape':
root.destroy()
def Quit():
quitask = tkinter.messagebox.askquestion("Quit", "Are you sure you want to quit?")
if quitask == "yes":
root.destroy()
def Insert():
filen = askopenfilename()
filen1 = tkinter.messagebox.showinfo("Saved", "If you opened a picture we saved it!")
firstname = Label(root, text="First Name",font=("Helvetica", 12),fg="green")
lastname = Label(root, text="Last Name",font=("Helvetica", 12),fg="green")
time = Label(root, text=current_time, font=("Helvetica", 12),fg="black")
TextArea = Text()
ScrollBar = Scrollbar(root)
ScrollBar.config(command=TextArea.yview)
TextArea.config(yscrollcommand=ScrollBar.set)
ScrollBar.pack(side=RIGHT, fill=Y)
Submit = Button(root, fg="white", bg="green", text="Submit", width=50, command=Submit, activebackground="yellow")
Quit = Button(root, fg="white", bg="green", text="Quit", width=50, command=Quit,activebackground="yellow")
Insert = Button(root,fg="white", bg="green", text="Insert Images", width=50, command=Insert,activebackground="yellow")
root.bind_all('<Key>', keypress)
firstname.pack()
e1.pack()
lastname.pack()
e2.pack()
time.pack()
TextArea.pack(expand=YES, fill=BOTH)
Insert.pack()
Submit.pack()
Quit.pack()
mainloop()
The problem is this line of code:
fullname = "%s %s" % (e1, e2)
e1 and e2 are entry widgets. Their string representation (ie: if you do str(e1)) is going to be "a weird decimal number".
You need to be calling the get() method of the widget to get the contents:
fullname = "%s %s" % (e1.get(), e2.get())

Python Tkinter error: "Label has no __call__method"

Im trying to create a Python tkinter login registeration but running into a small issue.
The error message is:
self.Label_Name = Label(top, text="What is your username: ")
AttributeError: Label instance has no __call__ method
Please can you proof read my code:
from Tkinter import *
class Register:
def __init__(self, parent):
top = self.top = Toplevel(parent)
# Variables to store the entries
self.VarEntUser = StringVar()
self.VarEntPass = StringVar()
self.VarEntRetype = StringVar()
self.Label_Name = Label(top, text="What is your username: ")
self.Label_Password = Label(top, text="Enter a password: ")
self.Label_Retype = Label(top, text="Retype Password: ")
# Entry fields for the user to enter there details
self.Ent_Name = Entry(top, textvariable=self.VarEntUser)
self.Ent_Password = Entry(top, textvariable=self.VarEntPass)
self.Ent_Retype = Entry(top, textvariable=self.VarEntRetype)
# Puts all the fields ^, into the window
self.Label_Name.grid(row=0, sticky=W)
self.Label_Password.grid(row=1, sticky=W)
self.Label_Retype.grid(row=2, sticky=W)
self.Ent_Password.grid(row=1, column=1)
self.Ent_Retype.grid(row=2, column=1)
self.Ent_Name.grid(row=0, column=2)
# Run the RegisterCheck function
# submit button which Checks the Entered details then writes the user and pass to a .txt file
self.MySubmitButton = Button(top, text='Submit', command=RegisterCheck)
self.MySubmitButton.pack()
self.U = raw_input(self.VarEntUser.get())
self.P = raw_input(self.VarEntPass.get())
self.R = raw_input(self.VarEntRetype.get())
class LogIn:
def __init__(self, parent):
top = self.top = Toplevel(parent)
self.a = StringVar()
self.b = StringVar()
self.Label_Log_User1 = Label(top, text='Username:')
self.Label_Log_Pass = Label(top, text='Password: ')
self.Ent_User_Log = Entry(top, textvariable=self.a)
self.Ent_Pass_Log = Entry(top, textvariable=self.b)
self.Label_Log_User1.grid(row=1)
self.Pass_Log.grid(row=2)
self.EntUserLog.grid(row=1, column=1)
self.EntPassLog.grid(row=2, column=1)
self.User = raw_input(self.EntUserLog.get())
self.Pass = raw_input(self.EntUserLog.get())
# runs the 'LoginCheck' function
self.LogInButton = Button(top, text="Log In", command=LogInCheck)
self.LogInButton.pack()
def LogInCheck(self):
# Checks if the fields are blanking displaying an error
if len(self.User) <= 0 and len(self.Pass) <= 0:
print "Please fill in all fields."
else:
pass
# Checks to see if the user and pass have been created
if self.User in 'username.txt' and self.Pass in 'password':
print 'You are now logged in!'
else:
print "Log in Failed"
def RegisterCheck(self):
# Checks if the fields are blank
if len(self.P) <= 0 and len(self.U) <= 0:
print "Please fill out all fields."
else:
pass
# Check is the password and the retype match
if self.P == self.R:
pass
else:
print "Passwords do not match"
# After registering write the user and pass to a .txt file
with open('username.txt', 'a') as fout:
fout.write(self.U + '\n')
with open('password.txt', 'a') as fout:
fout.write(self.P + '\n')
# Depending on what the user chooses, either log in or register than opens the specific window
def launch_Register():
inputDialog = Register(root)
root.wait_window(inputDialog.top)
def launch_LogIn():
inputdialog2 = LogIn(root)
root.wait_window(inputdialog2.top)
root = Tk()
label = Label(root, text='Choose an option')
label.pack()
loginB = Button(root, text='Log In', command=launch_LogIn)
loginB.pack()
registerB = Button(root, text='Register', command=launch_Register)
registerB.pack()
root.mainloop()
The problem is that in this line
Label = Label(root, text='Choose an option')
you define a Label called Label, thus shadowing the Label constructor. Then, then you create the several labels in your Register and Login classes (triggered by those two buttons), the name Label is no longer bound to the constructor, but to that specific label.
Change the name of the label, then it should work. Also, I would advise you to use lower-case names for variables and methods. This alone might help prevent many such errors.
root = Tk()
label = Label(root, text='Choose an option')
label.pack()
loginB = Button(root, text='Log In', command=launch_LogIn)
loginB.pack()
registerB = Button(root, text='Register', command=launch_Register)
registerB.pack()
root.mainloop()
Note that there are a few many more problems with your code:
StringVar a and b should probably be self.a and self.b
You are trying to use raw_input to get the user input in the Entry widgets; this is wrong! Instead, just read the value of the variables to get the values, e.g. instead of self.User, use self.a.get()
do not mix grid and pack layout
if self.User in 'username.txt' will not check whether that name is in that file
loginCheck and registerCheck should be methods of the respective class
Once I'm at it, here's (part of) my version of your code, to help you getting started:
class Register:
def __init__(self, parent):
top = self.top = Toplevel(parent)
self.var_user = StringVar()
self.var_pass = StringVar()
self.var_retype = StringVar()
Label(top, text="What is your username: ").grid(row=0, sticky=W)
Label(top, text="Enter a password: ").grid(row=1, sticky=W)
Label(top, text="Retype Password: ").grid(row=2, sticky=W)
Entry(top, textvariable=self.var_user).grid(row=0, column=1)
Entry(top, textvariable=self.var_pass).grid(row=1, column=1)
Entry(top, textvariable=self.var_retype).grid(row=2, column=1)
Button(top, text='Submit', command=self.registerCheck).grid(row=3)
def registerCheck(self):
u, p, r = self.var_user.get(), self.var_pass.get(), self.var_retype.get()
if p and u:
if p == r:
logins[u] = p
else:
print "Passwords do not match"
else:
print "Please fill out all fields."
class LogIn:
# analogeous to Register; try to figure this out xourself
def launch_Register():
inputDialog = Register(root)
root.wait_window(inputDialog.top)
def launch_LogIn():
inputDialog = LogIn(root)
root.wait_window(inputDialog.top)
logins = {}
root = Tk()
Label(root, text='Choose an option').pack()
Button(root, text='Log In', command=launch_LogIn).pack()
Button(root, text='Register', command=launch_Register).pack()
root.mainloop()
Note that I changed the login "database" from files to a dictionary to keep things simple and to focus on the Tkinter problems. Of course, neither a simple dictionary nor a plain-text file is an appropriate way to store login information.
Also, I put the creation and the layout of the GUI widgets on one line. In this case this is possible since we do not need a reference to those widgets, but beware never to do e.g. self.label = Label(...).grid(...), as this will bind self.label to the result of grid, and not to the actual Label.
Finally, this will still print all the messages to the standard output. Instead, you should add another Label for that, or open a message dialogue, but this is left as an excercise to the reader...

Categories