[tkinter] Can i make an image larger than the canvas?

Post here if you need help with creating a Graphical User Interface in Python.

[tkinter] Can i make an image larger than the canvas?

Postby dannyxy » Wed Apr 24, 2013 10:26 pm

Is this possible because i am making a game and i want the floor where the is standing on to move to the each time i press the "->" key?
Thanks
dannyxy
 
Posts: 18
Joined: Fri Mar 29, 2013 11:26 am

Re: [tkinter] Can i make an image larger than the canvas?

Postby metulburr » Thu Apr 25, 2013 2:03 am

Again i didnt attempt to make a game in tkinter, as i switched to pygame once i decided to try to make games. Pygame has a lot of methods, class for such things, hense its name pygame.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1387
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: [tkinter] Can i make an image larger than the canvas?

Postby Mekire » Thu Apr 25, 2013 3:24 am

I haven't done a great deal with Tkinter either, but when I was messing around with it making this:
http://python-forum.org/viewtopic.php?f=12&t=1040
I did find that it seemed hard to maintain constant framerates but as said, my experience with it is limited.

If what you are wanting at the moment is just to create some simple 2-dimensional games then I would also suggest pygame. If you have a good grasp of python basics (including functions and classes) you should be able to pick it up at a fair pace. You also might want to look into pyglet. From what I hear pyglet is all-around slightly better but I haven't messed with it myself. It also supplies OpenGL bindings out of the box if/when you decide you want/need them. You can use OpenGL with pygame as well but it requires using the module pyOpenGL as well.

I can't really comment on which would be easier for you to pick up. I'm very comfortable with pygame so I haven't put in the work with pyglet yet. I'm sure if you stick with Tkinter you will probably be able to accomplish what you are aiming for; it just probably isn't the best way to go about it.

-Mek
User avatar
Mekire
 
Posts: 986
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: [tkinter] Can i make an image larger than the canvas?

Postby wuf » Thu Apr 25, 2013 8:16 am

Hi dannyxy
dannyxy wrote:Can i make an image larger than the canvas?

With Tkinter absolutely no problem:
Code: Select all
#!/usr/bin/env python
# -*- coding: utf-8 -*-

try:
    #~~ For Python 2.x
    import Tkinter as tk
except ImportError:
    #~~ For Python 3.x
    import tkinter as tk

BOARD_WIDTH = 400
BOARD_HEIGHT = 300

SHAPE_XORG = 100
SHAPE_YORG = 100
SHAPE_SIZE = 100
SHAPE_COLOR = 'green'
SHAPE_TAG = 'ballon'

SHAPE_GEOMETRY = (SHAPE_XORG, SHAPE_YORG, SHAPE_XORG+SHAPE_SIZE,
    SHAPE_YORG+SHAPE_SIZE)

SCALE_FAC = 1.1
SCALE_TIME_STEP = 50 # Milliseconds

def expand_shape():
   
    canvas.scale(SHAPE_TAG, SHAPE_XORG+SHAPE_SIZE/2, SHAPE_YORG+SHAPE_SIZE/2,
        SCALE_FAC, SCALE_FAC)
       
    x1, y1, x2, y2 = canvas.bbox(SHAPE_TAG)
   
    if x2 > BOARD_WIDTH:
        canvas.coords(SHAPE_TAG, SHAPE_GEOMETRY)
       
    canvas.after(SCALE_TIME_STEP, expand_shape)
   
app_win = tk.Tk()
app_win.title("Shape gets bigger as canvas")

# Create board
canvas = tk.Canvas(app_win, width=BOARD_WIDTH, height=BOARD_HEIGHT,
    bg='steelblue', highlightthickness=0)
canvas.pack()

# Create shape
canvas.create_oval(SHAPE_GEOMETRY, fill=SHAPE_COLOR, width=0,
    tag=SHAPE_TAG)

expand_shape()
   
app_win.mainloop()

Maybe i did misunderstood your question.

wuf ;)
wuf
 
Posts: 37
Joined: Fri Feb 08, 2013 6:42 am

Re: [tkinter] Can i make an image larger than the canvas?

Postby dannyxy » Thu Apr 25, 2013 11:04 am

Thanks but i installed pygame but it is very slow
dannyxy
 
Posts: 18
Joined: Fri Mar 29, 2013 11:26 am

Re: [tkinter] Can i make an image larger than the canvas?

Postby Mekire » Thu Apr 25, 2013 11:08 am

The installation is slow? Or your program is slow?

-Mek
User avatar
Mekire
 
Posts: 986
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: [tkinter] Can i make an image larger than the canvas?

Postby dannyxy » Thu Apr 25, 2013 11:27 am

My program
dannyxy
 
Posts: 18
Joined: Fri Mar 29, 2013 11:26 am

Re: [tkinter] Can i make an image larger than the canvas?

Postby Mekire » Thu Apr 25, 2013 12:43 pm

Well if you are now attempting to use pygame feel free to post your code and I'll see what I can do (probably in the games section).

-Mek
User avatar
Mekire
 
Posts: 986
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to GUI

Who is online

Users browsing this forum: No registered users and 3 guests