Jump to content

[Python] Speed Reader app with tkinter - no problem with running but the window doesn't appear

I made a speed reader app with python. (It is not complete but it should be enough for v1 and work.) When I run it a window doesn't appear. Do you have any idea what the source of the problem might be? When I try printing the text normally without using tkinter there is no problem.

 

CODE: This is not very short but I suspect most of it is irrelevant to the problem.

Spoiler
from tkinter import *
import os
import PyPDF2
import pyttsx3
import time
import easygui 
global word 
global currentword
global delay
currentword = 0
global new 
new = True
global id
global filename
global db
global past
def load():
    global db
    global filename
    global currentword
    global new
    db = open("database","w+")
    past = db.readlines()
    index = -1
    for i in past:
        index += 1
        if i[0] == filename:
            currentword = i[2]
            new  = False
            id = index
def getSpeed(wpm):
    wps = wpm/60
    delay = 1/wps
    return(delay)
def openFile():
    global filename
    file = easygui.fileopenbox()
    filename = file
    return file
def getTextFromPDF(location):
    output = ""
    book = open(location,"rb")
    pdfReader = PyPDF2.PdfFileReader(book)
    pageNumber = pdfReader.numPages
    for fakePageNum in range(pageNumber):
        pageNum = fakePageNum #"+1"
        page = pdfReader.getPage(pageNum)
        text = page.extractText()
        output += text
    return output
def display(textList,outsource):
    global delay
    global word
    global currentword
    for element in textList:
        time.sleep(delay)
        word = element
        currentword += 1
        outsource.configure(text=word)
        print(word)
def quitUp():
    global db
    global id
    global past
    global filename
    global currentword
    if new:
        db.write((filename,currentword))
    else:
        past[id][1] = currentword
    db.write(past)

#load()
delay = getSpeed(450)
filename = "Of Mice and Men - Full Text.pdf"
textlist = getTextFromPDF(filename)

word = 0

root = Tk()
label0 = Label(root,text = word)
label0.pack()
display(textlist,label0)
root.mainloop()

 

 

Link to post
Share on other sites

The GUI works fine for me under Python 2.7.13 (the one I easily have on hand now). In cases like this start small: does just the GUI part work? That is, ignore all your logic code, first try simply making a window appear.

 

Also as a side note don't use

from <package> import *

but rather explicitely import what you need.

Crystal: CPU: i7 7700K | Motherboard: Asus ROG Strix Z270F | RAM: GSkill 16 GB@3200MHz | GPU: Nvidia GTX 1080 Ti FE | Case: Corsair Crystal 570X (black) | PSU: EVGA Supernova G2 1000W | Monitor: Asus VG248QE 24"

Laptop: Dell XPS 13 9370 | CPU: i5 10510U | RAM: 16 GB

Server: CPU: i5 4690k | RAM: 16 GB | Case: Corsair Graphite 760T White | Storage: 19 TB

Link to post
Share on other sites

8 hours ago, tikker said:

Works fine for me under Python 2.7.13 (the one I easily have on hand now). In cases like this start small: does just the GUI part work? That is, ignore all your logic code, first try simply making a window appear.

 

Also as a side note don't use

from <package> import *

but rather explicitely import what you need.

I tried it,no problem with the gui either.

 

is this fine:

import tkinter

 

Link to post
Share on other sites

4 hours ago, Wictorian said:

I tried it,no problem with the gui either.

Which platform, Python version and Tkinter version are you using? The window was super small, is it perhaps hiding on a secondary screen or behind something? If the GUI on its own works fine then something about your other code is making it close/disappear.

4 hours ago, Wictorian said:

is this fine:

import tkinter

 

Sure, but you'll have to adapt your code to it. It's more the fact that import * is considered bad practise, because essentially you don't know what you are importing into the namespace which may have subtle unintended consequences. In your case you could do for example

from tkinter import Tk,Label

 

Crystal: CPU: i7 7700K | Motherboard: Asus ROG Strix Z270F | RAM: GSkill 16 GB@3200MHz | GPU: Nvidia GTX 1080 Ti FE | Case: Corsair Crystal 570X (black) | PSU: EVGA Supernova G2 1000W | Monitor: Asus VG248QE 24"

Laptop: Dell XPS 13 9370 | CPU: i5 10510U | RAM: 16 GB

Server: CPU: i5 4690k | RAM: 16 GB | Case: Corsair Graphite 760T White | Storage: 19 TB

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×