Python Forum
Display text 3 words at a time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Display text 3 words at a time
#1
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
Reply
#2
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
Reply
#3
(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
Reply
#4
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
Reply
#5
(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
Reply
#6
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()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Scaling text QLabel following display mode windows '100%, 125% ...) VIGNEAUD 2 2,217 Jul-07-2021, 06:38 PM
Last Post: deanhystad
  Display MySQL data in QLlineEdit text boxes JayCee 1 4,051 Mar-26-2020, 03:55 PM
Last Post: JayCee
  Display and update the label text which display the serial value jenkins43 5 8,988 Feb-04-2019, 04:36 AM
Last Post: Larz60+
  Display more than one button in GUI to display MPU6000 Sensor readings barry76 4 3,833 Jan-05-2019, 01:48 PM
Last Post: wuf

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020