Python Forum
Display text 3 words at a time - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Display text 3 words at a time (/thread-26506.html)



Display text 3 words at a time - algae - May-04-2020

Hi,
I want to display 3 words on screen at a time from some textfile/pdf. At a specified rate (user to select time 1/100 to 300 sec).

I also want to provide a pause button( eg ENTER) and a resume button (ENTER)

f = open("demofile.txt", "r") 
for x in f: print(x) input()
 f.close()
The speed of display and the pause / resume buttons are a problem. Request for any help

thanks


RE: Display text 3 words at a time - DPaul - May-04-2020

Are you considering a GUI (Tkinter...) to display the words ?,
because printing will be very small for the user.
A GUI will solve that problem, and provide possibilities to select time
and proper buttons.

Paul


RE: Display text 3 words at a time - algae - May-05-2020

(May-04-2020, 03:00 PM)DPaul Wrote: Are you considering a GUI (Tkinter...) to display the words ?,
because printing will be very small for the user.
A GUI will solve that problem, and provide possibilities to select time
and proper buttons.

Paul

Hi Paul, Smile Thanks for the reply, Yes. Could you give it a decko ? Thanks


RE: Display text 3 words at a time - DPaul - May-10-2020

If this is your first GUI, i suggest someting simple:
- Find a tutorial on e.g. Tkinter, one with 'grid' positioning (not packing).
- The geometry will let you decide how big the app window will be, the next 5 items must fit in (width, height)
- Start with 3 Labels for the words
- The A Entry text box to type the duration (user)
- And on the fifth row (actually # 4) a button that says 'start'. When you press it it changes to "stop"
pressing start will validate the entered duration and start the show.
Paul


RE: Display text 3 words at a time - algae - Jun-27-2020

(May-10-2020, 06:31 AM)DPaul Wrote: If this is your first GUI, i suggest someting simple:
- Find a tutorial on e.g. Tkinter, one with 'grid' positioning (not packing).
- The geometry will let you decide how big the app window will be, the next 5 items must fit in (width, height)
- Start with 3 Labels for the words
- The A Entry text box to type the duration (user)
- And on the fifth row (actually # 4) a button that says 'start'. When you press it it changes to "stop"
pressing start will validate the entered duration and start the show.
Paul
Thank you Paul Smile


RE: Display text 3 words at a time - menator01 - Jun-27-2020

Here is an example in tkinter. I originally did this for changing background images but, modified for text.
Take a look and dissect it, You can get a basic understanding of countdown timers.
Here is an example of an alarm clock I did, if you would rather do it based on time.

#! /usr/bin/env python3

from tkinter import *
from tkinter import ttk



class Picture:
    def __init__(self, parent):
        self.parent = parent
        style = ttk.Style()
        style.configure('My.TLabel',padding=.85, borderwidth=1, relief='solid')
        self.label = ttk.Label(self.parent, style='My.TLabel')
        self.label['text'] = 'Start text here'
        self.label.pack(pady=15)

        btn = Button(self.parent, command=self.update, text='Change Text').pack(side='bottom', pady=10)

        self.lab = Label(self.parent)
        self.lab['text'] = None
        self.lab.pack(expand=True, fill='x')





    def update(self):
        self.label['text'] = 'Next Text Here'
        self.label['foreground'] = 'red'
        self.i = 8
        self.timer()

    def display(self):
        self.label['text'] = 'Last Text Here'
        self.label['foreground'] = 'green'

    def run_timer(self):
        if self.i >= 0:
            self.i -= 1

    def timer(self):
        self.run_timer()
        if self.i >= 0:
            self.myvar = self.lab.after(1000, self.timer)
            self.lab['text'] = f'Text reset in {self.i}'
            self.lab['bg'] = 'burlywood'
            self.lab['fg'] = 'firebrick'
            self.lab['font'] = 'serif 10 normal'
        else:
            self.myvar = None
            self.lab['text'] = ''
            self.lab['bg'] = 'grey86'
            self.display()



def main():
    root = Tk()

    Picture(root)
    root.mainloop()

main()