Autoclicker Tkinter Program I made my first program that I might actually use and I was wondering if anyone had some tips on how I could improve it.

My code is an auto-clicker that uses Python3 ctypes for the clicking and Tkinter for the GUI. I made this in 2 hours so there might be a lot of optimization I could do.

from tkinter import *
from tkinter import ttk
import ctypes
import time

mouse = ctypes.windll.user32
state = False

def StateFalse():
     global state
     global x
     if state == True:
          state = False
          x = 0

def StateTrue():
     global state
     global x
     if state == True:
          state = True
     else:
          x = 0
          state = True

root = Tk()
root.title("AutoClicker")
root.resizable(width=FALSE, height=FALSE)

amount = StringVar()
speed = StringVar()

amount.set(0)
speed.set(100)
mainframe = ttk.Frame(root)
mainframe.grid(padx=5, pady=5)

amountLabel = ttk.Label(mainframe, text="Number of Clicks\n(set to 0 for infinite)").grid(column=1, row=1, sticky=W)
speedLabel = ttk.Label(mainframe, text="Click interval\n(In milliseconds)").grid(column=1, row=2, sticky=W)
amountEntry = ttk.Entry(mainframe, textvariable=amount, width=5).grid(column=2, row=1)
speedEntry = ttk.Entry(mainframe, textvariable=speed, width=5).grid(column=2, row=2)
startButton = ttk.Button(mainframe, text="Start", width=10, command=StateTrue).grid(column=1, row=3,columnspan=2,sticky=W)
stopButton = ttk.Button(mainframe, text="Stop", width=10, command=StateFalse).grid(column=2, row=3, columnspan=2,sticky=E)

mainframe.bind("&lt;F1&gt;",StateTrue())
mainframe.bind("&lt;F3&gt;",StateFalse())

timekeeper = 0
x = 0

while True:
     timekeeper += 1
     if state == True:
          Amount = int(amount.get())
          Speed = int(speed.get())
          print(state)
          if Amount == 0:
               time.sleep(Speed / 1000)
               mouse.mouse_event(2, 0, 0, 0, 0)  # left mouse button down
               mouse.mouse_event(4, 0, 0, 0, 0)  # left mouse button up
               x += 1
               print("Clicked %s Times" % (x))

          elif x &lt; Amount and state == True:
               time.sleep(Speed / 1000)
               mouse.mouse_event(2, 0, 0, 0, 0)  # left mouse button down
               mouse.mouse_event(4, 0, 0, 0, 0)  # left mouse button up
               x += 1
               print("Clicked %s Times" % (x))
               if x == Amount:
                    state = False
     root.update()
You are using global variables and connecting them with the functions StateFalse and StateTrue. It would be better to read and write the configuration options to a file.

def set_option(value):
    with open(CONFIG_FILE,"w+") as f:
        f.write(value)

def get_option():
    with open(CONFIG_FILE) as f:
        return f.read() == "True"


Where CONFIG_FILE is a filename of your choice that you choose to store the "state" (maybe you should find a better name).