Python Forum
[Tkinter] scrolling text in tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] scrolling text in tkinter
#3
Are you set on tkinter? Or can it be any library? 
Often use this as a credit screen for resources, developers, etc. for games. Thus the reason why its in pygame.

import pygame as pg
 
pg.init()
 
text_list = '''I'm Henry the eighth, I am
Henry the eighth, I am, I am
I got married to the widow next door
She's been married seven times before
 
And every one was an Henry (Henry)
She wouldn't have a Willy or a Sam (No Sam)
I'm her eighth old man, I'm Henry
Henry the eighth I am
 
Second verse, same as the first
 
I'm Henry the eighth, I am
Henry the eighth, I am, I am
I got married to the widow next door
She's been married seven times before
 
And every one was an Henry (Henry)
She wouldn't have a Willy or a Sam (No Sam)
I'm her eighth old man, I'm Henry
Henry the eighth I am
 
I'm Henry the eighth, I am
Henry the eighth, I am, I am
I got married to the widow next door
She's been married seven times before
 
And every one was an Henry (Henry)
She wouldn't have a Willy or a Sam (No Sam)
I'm her eighth old man, I'm Henry
Henry the eighth I am
 
H-E-N-R-Y
Henry (Henry)
Henry (Henry)
Henry the eighth I am, I am
Henry the eighth I am
Yeah!
'''.split('\n')
 
class Credits:
    def __init__(self, screen_rect, lst):
        self.srect = screen_rect
        self.lst = lst
        self.size = 16
        self.color = (255,0,0)
        self.buff_centery = self.srect.height/2 + 5
        self.buff_lines = 50
        self.timer = 0.0
        self.delay = 0
        self.make_surfaces()
 
 
    def make_text(self,message):
        font = pg.font.SysFont('Arial', self.size)
        text = font.render(message,True,self.color)
        rect = text.get_rect(center = (self.srect.centerx, self.srect.centery + self.buff_centery) )
        return text,rect
 
    def make_surfaces(self):
        self.text = []
        for i, line in enumerate(self.lst):
            l = self.make_text(line)
            l[1].y += i*self.buff_lines
            self.text.append(l)
 
    def update(self):
        if pg.time.get_ticks()-self.timer > self.delay:
            self.timer = pg.time.get_ticks()
            for text, rect in self.text:
                rect.y -= 1
 
    def render(self, surf):
        for text, rect in self.text:
            surf.blit(text, rect)
 
screen = pg.display.set_mode((800,600))
screen_rect = screen.get_rect()
clock = pg.time.Clock()
done = False
cred = Credits(screen_rect, text_list)
pg.mixer.music.load("filename.mp3")
pg.mixer.music.play()
 
while not done:
    for event in pg.event.get(): 
        if event.type == pg.QUIT:
            done = True
    screen.fill((0,0,0))
    cred.update()
    cred.render(screen)
    pg.display.update()
    clock.tick(60)
Recommended Tutorials:
Reply


Messages In This Thread
scrolling text in tkinter - by Barrowman - Oct-18-2016, 06:24 PM
RE: scrolling text in tkinter - by nilamo - Oct-18-2016, 07:41 PM
RE: scrolling text in tkinter - by metulburr - Oct-18-2016, 08:09 PM
RE: scrolling text in tkinter - by Barrowman - Oct-18-2016, 08:45 PM
RE: scrolling text in tkinter - by nilamo - Oct-18-2016, 09:04 PM
RE: scrolling text in tkinter - by Barrowman - Oct-18-2016, 09:55 PM
RE: scrolling text in tkinter - by metulburr - Oct-18-2016, 08:51 PM
RE: scrolling text in tkinter - by Barrowman - Oct-18-2016, 09:02 PM
RE: scrolling text in tkinter - by nilamo - Oct-18-2016, 10:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Updating tkinter text BliepMonster 5 6,469 Nov-28-2022, 01:42 AM
Last Post: deanhystad
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 5,269 Jun-26-2022, 06:26 PM
Last Post: menator01
  tkinter change the text of the checkbox zazas321 1 3,949 Sep-17-2021, 06:19 AM
Last Post: zazas321
  tkinter text widget word wrap position chrisdb 6 7,740 Mar-18-2021, 03:55 PM
Last Post: chrisdb
  [Tkinter] tkinter.Menu – How to make text-variable? Sir 3 5,746 Mar-10-2021, 04:21 PM
Last Post: Sir
  tkinter touchscreen scrolling - button press makes unwanted scrolling nanok66 1 4,100 Dec-28-2020, 10:00 PM
Last Post: nanok66
Photo Tkinter TEXT background image _ShevaKadu 5 7,960 Nov-02-2020, 10:34 AM
Last Post: joe_momma
  tkinter | Button color text on Click Maryan 2 3,462 Oct-09-2020, 08:56 PM
Last Post: Maryan
  [Tkinter] Text Upload LearningLittlebyLittle 0 2,089 Sep-04-2020, 07:55 PM
Last Post: LearningLittlebyLittle
  [Tkinter] Indentation for Tkinter-made Text Editor ShakeyPakey 4 5,257 Jun-08-2020, 03:13 PM
Last Post: menator01

Forum Jump:

User Panel Messages

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