#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Exclamation Tkinter script not displaying anything


    hi, I have a script in which there's a Tkinter window and a function that types everyting out gradually.
    however, nothing is displayed when I launch the script, not even the colours! how come?

    here's the code:

    Code:
    import Tkinter as tk
    import tkFont, pygame, time, os, random
    file = '/home/<username>/file.mp3'
    pygame.init()
    pygame.mixer.init()
    pygame.mixer.music.load(file)
    pygame.mixer.music.play()
    class App:
      def __init__(self):
        self.root=tk.Tk()
        self.root.resizable(0,0)
        self.textvar    = tk.StringVar()
        self.picvar     = tk.StringVar()
        self.customFont = tkFont.Font(family="Courier", size=12)
        self.text       = tk.Label(self.root, anchor=tk.NW, justify=tk.LEFT, width=50, height=12, font=self.customFont, bg="black", fg="yellow", textvariable = self.textvar)
        self.pic        = tk.Label(self.root, anchor=tk.NW, width=50, height=20, font=self.customFont, bg="black", fg="yellow", textvariable = self.picvar)
        self.root.after(0, self.starttyping)
        self.root.mainloop()
      def update(self):
        self.textvar.set(self.textvar.get()+self.char)
      def xchar(self, phase, delay):
        for char in phase:
          self.time=int(delay)
          self.char=char
          self.root.after(self.time,self.update)
      def starttyping(self):
          self.xchar('Hello!', 80)
    app=App()
    P.S.: the pygame is to start the music in the backgound.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,851
    Rep Power
    481
    You need to pack the "widgets" (or place them or grid them or perhaps create_window(position, **options) onto a canvas).
    Code:
    import Tkinter as tk
    import tkFont, pygame, time, os, random
    file = '/home/lambertdw/DWLPersonal/OhBrother/cleaned/Pitches.mp3'
    pygame.init()
    pygame.mixer.init()
    pygame.mixer.music.load(file)
    pygame.mixer.music.play()
    class App:
      def __init__(self):
        self.root=tk.Tk()
        self.root.resizable(0,0)
        self.textvar    = tk.StringVar()
        self.picvar     = tk.StringVar()
        self.customFont = tkFont.Font(family="Courier", size=12)
        self.text       = tk.Label(self.root, anchor=tk.NW, justify=tk.LEFT, width=50, height=12, font=self.customFont, bg="black", fg="yellow", textvariable = self.textvar)
        self.text.pack()################################################################
        self.pic        = tk.Label(self.root, anchor=tk.NW, width=50, height=20, font=self.customFont, bg="black", fg="yellow", textvariable = self.picvar)
        self.pic.pack()################################################################
        self.root.after(0, self.starttyping)
        self.root.mainloop()
      def update(self):
        self.textvar.set(self.textvar.get()+self.char)
      def xchar(self, phase, delay):
        for char in phase:
          self.time=int(delay)
          self.char=char
          self.root.after(self.time,self.update)
      def starttyping(self):
          self.xchar('Hello!', 80)
    app=App()
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo