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

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Sizing canvas in IDLE


    Hi everyone,

    I'm trying to create the illusion of an interface in python. I'm only using IDLE to write the code right now which I believe has tkinter build in. I want to create a test game with the canvas being set inside of a tick black border with text rolling at the bottom below the canvas. How does that work exactly? And what if I wanted to use the mouse to select options on the canvas? thanks!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480

    scrolled text example


    Also investigate events and bindings
    Code:
    import sys
    
    if '2' == sys.version[0]:
        import Tkinter as tkinter
    else:
        import tkinter
    
    root = tkinter.Tk()
    canvas = tkinter.Canvas(root,width=400,height=100)
    canvas.pack()
    y = 100
    scroll = canvas.create_text(0,y,anchor=tkinter.NW,text="""$ python3 q.py
    Traceback (most recent call last):
      File "q.py", line 12, in <module>
        scroll.pack(tkinter.BOTTOM)
      File "/usr/lib/python3.2/tkinter/__init__.py", line 1819, in pack_configure
        + self._options(cnf, kw))
      File "/usr/lib/python3.2/tkinter/__init__.py", line 1066, in _options
        for k, v in cnf.items():
    AttributeError: 'str' object has no attribute 'items'""")
    
    def f(*args,**kwargs):
        global y
        y -= 1
        canvas.coords(scroll,0,y)
        if y < -160:
            root.destroy()
        else:
            canvas.after(20,f)
    
    canvas.after(40,f)
    
    root.mainloop()
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Hey thanks I'll sit and look over this! Seems much more obvious now

IMN logo majestic logo threadwatch logo seochat tools logo