Unexpected Tkinter error

I was just making a study program (for personal use) when I came across this error with tkinter

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import pyttsx3
from tkinter import *
from pynput.mouse import Button, Controller
from pynput.keyboard import Key, Controller as KB
import time

DriverPath = "C:\Program Files (x86)\msedgedriver"

Announcer = pyttsx3.init()
Mouse = Controller()
Keyboard = KB()

def StartStudyTime():
    Announcer.say("Starting study time please wait")
    Announcer.runAndWait()
    Browser = webdriver.Edge(DriverPath)
    Announcer.say("Opening OneNote for making notes")
    Announcer.runAndWait()
    Announcer.say("Please type the heading of the notes page")
    Announcer.runAndWait()
    UserInput = input("Enter the heading: ")
    Mouse.position = (435, 880)
    Mouse.click(Button.left, 1)
    time.sleep(6)
    Mouse.position = (1465, 249)
    Mouse.click(Button.left, 1)
    Keyboard.type(UserInput)
    Announcer.say("Opening pomodoro timer")
    Announcer.runAndWait()
    Browser.get("https://pomodorotimer.online/?standalone=true")
    PomodoroTimer = Browser.find_element_by_link_text("START")
    PomodoroTimer.click()
    Announcer.say("Successfully opened everything, now it's time to study!")
    Announcer.runAndWait()

Window = Tk()
StartStudyButton = Button(Window, text="Press to start study setup!", command=StartStudyTime)
StartStudyButton.grid(row=5, column=5)
mainloop()

In the StartStudyButton line it says that text is not recognized

I don’t why, I even closed the mainloop

There’s no error with Tkinter: if I strip out everything that has nothing to do with Tkinter, I have this…

from tkinter import *

def StartStudyTime():
    return

Window = Tk()
StartStudyButton = Button(Window, text="Press to start study setup!", command=StartStudyTime)
StartStudyButton.grid(row=5, column=5)
mainloop()

… which works just fine.

1 Like

Hey @rob42, Thanks for the help. The problem was that I imported Tkinter before the function as I wanted all of the imports to be in one group. Now when I cleaned up the code and made it clean, by importing it right above the UI code. Thanks for the help!

No worries; good that you’ve sussed it :sunglasses:

Enjoy your day.

1 Like