Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is this -Command error and how do i get rid of it?

So I’ve been following a online tutorial and writing it myself so I could get used to the errors, but I now have a error "unknown Option "-Command"

It seems to only effect the ok button that should close the window.

Any help into understanding the problem and how to get rid of it would be greatly appreciated

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

in order to make user file for login, simply create a document titled "user" with text in document as:
user
123

This will be the username and password for login

Code is below:

from tkinter import *
import os

def delete2():
    screen3.destroy()
   
def delete3():
    screen4.destry()
   
def delete4():
    screen5.destroy()
   
def login_sucess():
    global screen3
    screen3 = Toplevel(screen)
    screen3.title("Sucess")
    screen3.geometry("150x100")
    Label(screen3, text = "Login Sucess").pack()
    Button(screen3, text = "OK", Command =delete2).pack()

def password_not_recognised():
    global screen4
    screen4 = Toplevel(screen)
    screen4.title("Sucess")
    screen4.geometry("150x100")
    Label(screen4, text = "Password Error").pack()
    Button(screen4, text = "OK", Command =delete2).pack()
   
def user_not_found():
    global screen5
    screen5 = Toplevel(screen)
    screen5.title("Sucess")
    screen5.geometry("150x100")
    Label(screen5, text = "User Not Found").pack()
    Button(screen5, text = "OK", Command =delete2).pack()
   
def login_verify():
    username1 = username_verify.get()
    password1 = password_verify.get()
    username_entry1.delete(0, END)
    password_entry1.delete(0, END)
   
    list_of_files = os.listdir()
    if username1 in list_of_files:
        file1 = open(username1, "r")
        verify = file1.read().splitlines()
        if password1 in verify:
            login_sucess()
        else:
            password_not_recognised()
           
    else:
        user_not_found()
       
   
def login():
    global screen2
    screen2 = Toplevel(screen)
    screen2.title("Login")
    screen2.geometry("300x250")
    Label(screen2, text = "please enter details below to login").pack()
    Label(screen2, text = "").pack()
   
    global username_verify
    global password_verify
   
    username_verify = StringVar()
    password_verify = StringVar()
   
    global username_entry1
    global password_entry1
   
    Label(screen2, text = "Username * ").pack()
    username_entry1 = Entry(screen2, textvariable = username_verify)
    username_entry1.pack()
    Label(screen2, text = "").pack()
    Label(screen2, text = "Password * ").pack()
    password_entry1 = Entry(screen2, textvariable = password_verify)
    password_entry1.pack()
    Label(screen2, text = "").pack()
    Button(screen2, text = "Login", width = 10, height = 1, command = login_verify).pack()
   
def main_screen():
    global screen
    screen = Tk()
    screen.geometry("300x250")
    screen.title("Remote Monitoring Site 1")
    Label(text = "Remote Monitoring Site 1", bg = "grey", width = "300", height = "2", font = ("Calibri", 13)).pack()
    Label(text = "").pack()
    Button(text = "Login", width = "30", height = "2", command = login).pack()
    Label(text = "").pack()
    Button(text = "Register", width = "30", height = "2", command = register).pack()
   
    screen.mainloop()
   
main_screen()

Full error is as follows:

self.tk.call(
_tkinter.TclError: unknown option "-Command"

I have tried researching but have found no solution to my issue.

>Solution :

Options for python functions are case-sensitive, meaning command (which is the option you want to set) is not the same as Command. Change Button(screen4, text = "OK", Command =delete2).pack() to Button(screen4, text = "OK", command =delete2).pack() in all instances.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading