title: How to change input command with button in Tkinter?
body: <p>I'm making a virtual assistant and I'm designing the interface for it. In line number 219-220 I want the input command to be replaced by a button in Tkinter but it fails when I log in, the virtual assistant greets me and doesn't show up on the interface screen and keeps saying &quot;you:&quot; &quot;Jarvis:&quot;. I need your help thanks</p>
  <p>Here is my code</p>
  <pre><code>#import modules
  
  from tkinter import *
  import os
  import subprocess
  import datetime
  import os
  import pyjokes
  import pyttsx3
  import pywhatkit
  import requests
  import smtplib
  import speech_recognition as sr
  import webbrowser as we
  from datetime import date
  from newsapi import NewsApiClient
  import random
  import os
  import wikipedia
  from typing import Text
  import time
  from tkinter import *
  import os
  from tkinter import messagebox
  import sys
  import subprocess
  
  # Designing window for registration
  
  
  def register():
      def exit():
          register_screen.destroy()
  
      global register_screen
      register_screen = Toplevel(main_screen)
      register_screen.title(&quot;Sign in&quot;)
      register_screen.geometry(&quot;400x350&quot;)
      register_screen.configure(bg='#80ffff')
  
      global username
      global password
      global name
      global name_entry
      global dob
      global dob_entry
      global username_entry
      global password_entry
      username = StringVar()
      password = StringVar()
      name = StringVar()
      dob = StringVar()
  
      sign_in = Label(register_screen, text=&quot;Sign in&quot;, bg=&quot;#ff8533&quot;,
                      width=&quot;40&quot;, height=&quot;2&quot;, font=(&quot;Calibri&quot;, 15))
      sign_in.place(x=0, y=0)
  
      username_lable = Label(register_screen, height=2,
                             text=&quot;Username *&quot;, font=&quot;25&quot;, bg=&quot;#ff80ff&quot;, width=&quot;15&quot;)
      username_lable.place(x=20, y=70)
  
      username_entry = Entry(register_screen, width=30,
                             fg=&quot;#5c5c3d&quot;, textvariable=username)
      username_entry.place(x=170, y=83)
  
      password_lable = Label(register_screen, height=2,
                             text=&quot;Password * &quot;, font=&quot;25&quot;, bg=&quot;#ffff33&quot;, width=&quot;15&quot;)
      password_lable.place(x=20, y=120)
  
      password_entry = Entry(register_screen, width=30,
                             fg=&quot;#5c5c3d&quot;, textvariable=password, show='*')
      password_entry.place(x=170, y=133)
  
      name_lable = Label(register_screen, height=2,
                         text=&quot;Enter your name&quot;, font=&quot;25&quot;, bg=&quot;#ff3333&quot;, width=&quot;15&quot;)
      name_lable.place(x=20, y=170)
  
      name_entry = Entry(register_screen, width=30,
                         fg=&quot;#5c5c3d&quot;, textvariable=name)
      name_entry.place(x=170, y=183)
  
      Label(register_screen, text=&quot;&quot;).pack()
      exitButton = Button(register_screen, text=&quot;Exit&quot;, bg=&quot;red&quot;,
                          fg=&quot;white&quot;, width=4, font=7, command=exit).place(x=190, y=230)
      Button(register_screen, text=&quot;Register&quot;, width=8, bg=&quot;#00ff00&quot;,
             font=7, command=register_user).place(x=270, y=230)
  
  
  # Designing window for login
  
  def login():
      def exit2():
          login_screen.destroy()
  
      global login_screen
      login_screen = Tk
      login_screen = Toplevel(main_screen)
      login_screen.title(&quot;Login&quot;)
      login_screen.configure(bg='#ffb3b3')
      login_screen.geometry(&quot;400x350&quot;)
      Label(login_screen, text=&quot;Please enter details below to login&quot;,
            bg=&quot;#d966ff&quot;, font=&quot;30&quot;, width=300, height=3).pack()
      Label(login_screen, text=&quot;&quot;).pack()
  
      global username_verify
      global password_verify
  
      username_verify = StringVar()
      password_verify = StringVar()
  
      global username_login_entry
      global password_login_entry
  
      Label(login_screen, text=&quot;Username * &quot;, font=&quot;25&quot;,
            bg=&quot;#80dfff&quot;, height=2).place(x=20, y=70)
  
      username_login_entry = Entry(
          login_screen, width=30, textvariable=username_verify)
      username_login_entry.place(x=150, y=83)
  
      Label(login_screen, text=&quot;Password * &quot;, font=&quot;25&quot;,
            bg=&quot;#1aff1a&quot;, height=2).place(x=20, y=120)
  
      password_login_entry = Entry(
          login_screen, width=30, textvariable=password_verify, show='*')
      password_login_entry.place(x=150, y=133)
  
      Button(login_screen, text=&quot;Login&quot;, width=10, height=1,
             bg=&quot;#ff471a&quot;, command=login_verify).place(x=252, y=183)
  
      Button(login_screen, text=&quot;Exit&quot;, bg=&quot;#ffff4d&quot;, width=6,
             height=1, command=exit2).place(x=180, y=183)
      login_screen.mainloop()
  
  # Implementing event on register button
  
  
  def register_user():
  
      username_info = username.get()
      password_info = password.get()
      name_info = name.get()
  
      file = open(username_info, &quot;w&quot;)
      file.write(username_info + &quot;\n&quot;)
      file.write(password_info + &quot;\n&quot;)
      file.write(name_info + &quot;\n&quot;)
      file.close()
  
      username_entry.delete(0, END)
      password_entry.delete(0, END)
      name_entry.delete(0, END)
  
      register_screen.destroy()
  # Implementing event on login button
  
  
  def login_verify():
      username1 = username_verify.get()
      password1 = password_verify.get()
      username_login_entry.delete(0, END)
      password_login_entry.delete(0, END)
  
      list_of_files = os.listdir()
      if username1 in list_of_files:
          file1 = open(username1, &quot;r&quot;)
          verify = file1.read().splitlines()
          if password1 in verify:
              Jarvis_assistant()
  
          else:
              password_not_recognised()
  
      else:
          user_not_found()
  
  # Designing popup for login success
  
  
  def Jarvis_assistant():
  
      global login_success_screen
      login_success_screen = Toplevel(login_screen)
      login_success_screen.title(&quot;Success&quot;)
      login_success_screen.geometry(&quot;150x100&quot;)
      Label(login_success_screen, text=&quot;Login Success&quot;).pack()
  
      user = &quot;Mr.Stark&quot;  # your name
      assistant = &quot;Jarvis&quot;  # Iron man Fan
  
      Jarvis_mouth = pyttsx3.init()
      Jarvis_mouth.setProperty(&quot;rate&quot;, 165)
      voices = Jarvis_mouth.getProperty(&quot;voices&quot;)
  
      # For Mail voice AKA Jarvis
      Jarvis_mouth.setProperty(&quot;voice&quot;, voices[1].id)
  
      def Jarvis_brain(audio):
          robot = Jarvis_brain
          print(&quot;Jarvis: &quot; + audio)
          Jarvis_mouth.say(audio)
          Jarvis_mouth.runAndWait()
  
      #Jarvis speech
      #Jarvis_ear = listener
      #Jarvis_brain = speak
      #Jarvis_mouth = engine
      #you = command
  
      def inputCommand():
          # you = input() # For getting input from CLI
          Jarvis_ear = sr.Recognizer()
          you = &quot;&quot;
          with sr.Microphone(device_index=1) as mic:
              Jarvis_ear.pause_threshold = 1
              try:
                  Button(login_screen, text=&quot;Press to listen...&quot;, bg=&quot;#ffff4d&quot;, width=6,
                          height=1, command=inputCommand).place(x=0, y=50)
                  #input(&quot;Press to listen...&quot;) instead of using input I want to change this in to a button on tkinter
                  print(&quot;Listening...&quot;)
                  you = Jarvis_ear.recognize_google(
                      Jarvis_ear.listen(mic), language=&quot;en-IN&quot;)
              except Exception as e:
                  Jarvis_brain(&quot; &quot;)
              except:
                  you = &quot;&quot;
              print(&quot;You: &quot; + you)
  
          return you
  
      def greet():
          hour = datetime.datetime.now().hour
          if hour &gt;= 0 and hour &lt; 12:
              main_screen.destroy()
              Jarvis_brain(f&quot;Hello, Good Morning {user}&quot;)
              print(&quot;Hello,Good Morning&quot;)
          elif hour &gt;= 12 and hour &lt; 18:
              main_screen.destroy()
              Jarvis_brain(f&quot;Hello, Good Afternoon {user}&quot;)
              print(&quot;Hello, Good Afternoon&quot;)
          else:
              main_screen.destroy()
              Jarvis_brain(f&quot;Hello, Good Evening {user}&quot;)
              print(&quot;Hello,Good Evening&quot;)
      greet()
  
      def main():
          while True:
              # Getting input from the user
              you = inputCommand().lower()
              #General question.
              if (&quot;hello&quot; in you) or (&quot;Hi&quot; in you):
                  Jarvis_brain(random.choice(
                      [&quot;how may i help you, sir.&quot;, &quot;Hi,sir&quot;]))
  
              elif (&quot;time&quot; in you):
                  now = datetime.datetime.now()
                  robot_brain = now.strftime(&quot;%H hour %M minutes %S seconds&quot;)
                  Jarvis_brain(robot_brain)
  
              elif (&quot;date&quot; in you):
                  today = date.today()
                  robot_brain = today.strftime(&quot;%B %d, %Y&quot;)
                  Jarvis_brain(robot_brain)
  
              elif (&quot;joke&quot; in you):
                  Jarvis_brain(pyjokes.get_joke())
  
              elif &quot;president of America&quot; in you:
                  Jarvis_brain(&quot;Donald Trump&quot;)
  
              #open application
              elif (&quot;play&quot; in you):
                  song = you.replace('play', '')
                  Jarvis_brain('playing ' + song)
                  pywhatkit.playonyt(song)
  
              elif (&quot;open youtube&quot; in you):
                  Jarvis_brain(&quot;opening YouTube&quot;)
                  we.open('https://www.youtube.com/')
  
              elif (&quot;open google&quot; in you):
                  Jarvis_brain(&quot;opening google&quot;)
                  we.open('https://www.google.com/')
  
              elif &quot;information&quot; in you:
                  you = you.replace(&quot;find imformation&quot;, &quot;&quot;)
                  Jarvis_brain(&quot;what news you what to know about&quot;)
                  topic = inputCommand()
                  Jarvis_brain(&quot;open &quot; + topic)
                  we.open(&quot;https://www.google.com/search?q=&quot; + topic)
  
              elif (&quot;open gmail&quot; in you):
                  Jarvis_brain(&quot;opening gmail&quot;)
                  we.open('https://mail.google.com/mail/u/2/#inbox')
  
              elif &quot;vietnamese translate&quot; in you:
                  Jarvis_brain(&quot;opening Vietnamese Translate&quot;)
                  we.open('https://translate.google.com/?hl=vi')
  
              elif &quot;english translate&quot; in you:
                  Jarvis_brain(&quot;opening English Translate&quot;)
                  we.open(
                      'https://translate.google.com/?hl=vi&amp;sl=en&amp;tl=vi&amp;op=translate')
  
              elif (&quot;open internet&quot;) in you:
                  Jarvis_brain(&quot;opening internet&quot;)
                  openInternet = &quot;C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\Brave.exe&quot;
                  os.startfile(openInternet)
  
              elif &quot;wikipedia&quot; in you:
                  you = you.replace(&quot;wikipedia&quot;, &quot;&quot;)
                  Jarvis_brain(&quot;what topic you need to listen to&quot;)
                  topic = inputCommand()
                  results = wikipedia.summary(
                      topic, auto_suggest=False, redirect=True)
                  print(results)
                  Jarvis_brain(results)
  
          #New&amp;Covid-19
  
              elif (&quot;covid-19&quot; in you):
                  r = requests.get(
                      'https://coronavirus-19-api.herokuapp.com/all').json()
                  Jarvis_brain(
                      f'Confirmed Cases: {r[&quot;cases&quot;]} \nDeaths: {r[&quot;deaths&quot;]} \nRecovered {r[&quot;recovered&quot;]}')
  
              else:
                  if &quot;bye&quot; in you:
                      hour = datetime.datetime.now().hour
                      if (hour &gt;= 21) and (hour &lt; 5):
                          Jarvis_brain(f&quot;Good Night {user}! Have a nice Sleep&quot;)
                          exit()
                      else:
                          Jarvis_brain(f&quot;Bye {user}&quot;)
                          exit()
  
      main()
  
  
  # Designing popup for login invalid password
  def delete_password_not_recognised():
      password_not_recog_screen.destroy()
  
  
  def delete_user_not_found_screen():
      user_not_found_screen.destroy()
  
  
  def password_not_recognised():
      global password_not_recog_screen
      password_not_recog_screen = Toplevel(login_screen)
      password_not_recog_screen.title(&quot;Fail to login&quot;)
      password_not_recog_screen.geometry(&quot;250x150&quot;)
      password_not_recog_screen.configure(bg='#66ffff')
      Label(password_not_recog_screen, text=&quot;Invalid Password &quot;, font=&quot;30&quot;,bg=&quot;#ff99cc&quot;, width=&quot;30&quot;).pack()
      Button(password_not_recog_screen, text=&quot;Exit&quot;, bg=&quot;red&quot;, fg=&quot;white&quot;,
             width=5, command=delete_password_not_recognised).pack()
  
  # Designing popup for user not found
  
  
  def user_not_found():
      global user_not_found_screen
      user_not_found_screen = Toplevel(login_screen)
      user_not_found_screen.title(&quot;Fail to login&quot;)
      user_not_found_screen.geometry(&quot;250x150&quot;)
      user_not_found_screen.configure(bg='#66ffff')
      Label(user_not_found_screen, text=&quot;User Not Found&quot;,bg=&quot;#ff99cc&quot;, width=&quot;30&quot;, font=&quot;30&quot;).pack()
      Button(user_not_found_screen, text=&quot;Exit&quot;, bg=&quot;red&quot;, fg=&quot;white&quot;,
             width=5, command=delete_user_not_found_screen).pack()
  
  
  # Designing Main(first) window
  
  def main_account_screen():
      global main_screen
      main_screen = Tk()
      main_screen.geometry(&quot;500x350&quot;)
      main_screen.title(&quot;Account Login&quot;)
      main_screen.configure(bg='#ffcccc')
      Label(text=&quot;Sign in and Login in&quot;, bg=&quot;#00ffff&quot;, width=&quot;50&quot;,
            height=&quot;2&quot;, font=(&quot;Calibri&quot;, 15)).place(x=0, y=0)
      Label(text=&quot;&quot;).pack()
      Button(text=&quot;Login&quot;, height=&quot;2&quot;, width=&quot;30&quot;,
             command=login, bg=&quot;#1aff1a&quot;).place(x=140, y=80)
      Label(text=&quot;&quot;).pack()
      Button(text=&quot;Register&quot;, height=&quot;2&quot;, width=&quot;30&quot;,
             command=register, bg=&quot;#ff1a1a&quot;).place(x=140, y=150)
      main_screen.mainloop()
  
  
  main_account_screen()
  </code></pre>
  <p>And here is my terminal</p>
  <pre><code>    PS C:\Users\PC&gt; &amp; C:/Users/PC/AppData/Local/Programs/Python/Python39/python.exe c:/Users/PC/Desktop/lamdoan/loginform.py
  Jarvis: Hello, Good Evening Mr.Stark
  Hello,Good Evening
  Jarvis:  
  You: 
  Jarvis:  
  You: 
  Jarvis:  
  You: 
  Jarvis:  
  You: 
  Jarvis:  
  You: 
  Jarvis:  
  You: 
  Jarvis:  
  You: 
  Jarvis:  
  You: 
  Jarvis:  
  You: 
  Jarvis:  
  You: 
  Jarvis:  
  You: 
  Jarvis:  
  You: 
  </code></pre>