Hi,
I hv created an application with Tkinter/PIL in python25. It can import an image into the canvas. Now could someone kindly tell me how to select and move that image with mouse? Any help would be really appreciated. - # BirdaoGwra
-
# January 25, 2010
-
-
import sys, os, math
-
-
from Tkinter import *
-
import Tkinter as tk
-
import tkFileDialog as tkfd
-
import tkMessageBox as tkmb
-
-
import PIL as pil
-
from PIL import Image, ImageTk
-
-
myFormats = [
-
('Windows Bitmap', '*.bmp'),
-
('Portable Network Graphics', '*.png'),
-
('JPEG/JFIF', '*.jpg'),
-
('CompuServe GIF', '*.gif'),
-
('All File', '*.*')
-
]
-
-
class MyApp(object):
-
def __init__(self, master):
-
frame = tk.Frame(master)
-
frame.pack()
-
-
self.canvas = tk.Canvas(width=520, height=350)
-
self.canvas.pack()
-
self.canvas.config(borderwidth=1, bg='black')
-
-
# Create the menubar
-
menu = tk.Menu(master)
-
root.config(menu=menu)
-
# File menu
-
filemenu = tk.Menu(menu, tearoff=0)
-
menu.add_cascade(label="File", menu=filemenu)
-
filemenu.add_command(label="New Ctrl+N", command=self.new_file)
-
filemenu.add_command(label="Open... Ctrl+O", command=self.file_open)
-
filemenu.add_separator()
-
filemenu.add_command(label="Save... Ctrl+S")
-
filemenu.add_command(label="Save As... Ctrl+Shift+S", command=self.file_saveas)
-
filemenu.add_separator()
-
filemenu.add_command(label="Exit Ctrl+Q", command=self.do_exit)
-
-
def new_file(self):
-
"""create a new document"""
-
self.canvas.delete(ALL)
-
# self = tkmb.showinfo("Birdao Anime!", "Yet to implement!")
-
-
def file_open(self):
-
"""open a file to read"""
-
# self.canvas.delete(ALL)
-
filename = tkfd.askopenfilename(filetypes=myFormats)
-
if filename != '':
-
im = Image.open(filename)
-
if im.mode != "RGBA":
-
im = Image.open(filename).convert("RGBA")
-
source = im.split()
-
R, G, B, A = 0, 1, 2, 3
-
mask = im.point(lambda i: i> 0 and 255)
-
source[A].paste(mask)
-
im = Image.merge(im.mode, source)
-
-
self.graphic = ImageTk.PhotoImage(image=im)
-
self.canvas.create_image(100,100, image=self.graphic)
-
-
def file_saveas(self):
-
"""get a file name and save it"""
-
# no default file
-
filename = tkfd.asksaveasfile(filetypes=myFormats)
-
if filename:
-
self.saveimage.save(filename)
-
-
def do_exit(self):
-
root.destroy()
-
-
root = tk.Tk()
-
root.title("Birdao Anime 0.1")
-
root.config(bg='gray')
-
-
# use width x height + x_offset + y_offset (no spaces!)
-
root.geometry("%dx%d+%d+%d" % (640, 480, 120, 80))
-
myapp = MyApp(root)
-
root.mainloop()
And also how to center the canvas?
Thanks in advance
Regards
0 2042 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Marc |
last post by:
Hi all,
I was thinking about developing a drag and drop application and was curious
how difficult it is to do. Basically I want to have a set of objects that I
move around the screen and drop...
|
by: portraitmaker |
last post by:
I found some drag and drop code on the web and modified it a little b
taking out some of the stuff I didn't need.
This sample allows you to drag an image in a table to another positio
and swaps...
|
by: SamSpade |
last post by:
There seems to be two ways to put things on the clipboard ( I don't mean
different formats): SetClipboardData and OleSetClipboard
If I want to get data off the clipboard do I care how it was put...
|
by: Ajay Krishnan Thampi |
last post by:
I have a slight problem implementing 'drag and drop' from a datagrid
to a tree-view. I have pasted my code below. Someone please advice me
on what to do...pretty blur right now.
==code==
...
|
by: sebastian.janoschka |
last post by:
Hi,
I build my first Drag & Drop with JavaScript and I would like to drag
the pictures when I click on it.
When I create a normal div tag with some text the script works, but
when I put a...
| |
by: murrayatuptowngallery |
last post by:
I would like to have a slider or mouse position click capture means of
collecting a user input from a scale or ruler-like graphic.
I found some code snippets for mouse position capture on...
|
by: arvinds |
last post by:
I have an application in which I have 2 forms.
1.Review Form 2. FilmForm.
Review Form is used for Loading some images and we can transfer the
Images from Review From to FilmForm by Drag-Drop...
|
by: Romulo NF |
last post by:
Greetings,
I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
|
by: liangchen76 |
last post by:
Hey,
I am writing a web app to allow users to draw over an image. The workflow of drawing a rectangle is:
1. click a mouse button
2. hold and drag
3. while the mouse moving, the size of a...
|
by: Peter Pearson |
last post by:
Tkinter makes it very easy to drag jpeg images around on a
canvas, but I would like to have a "target" change color when
the cursor dragging an image passes over it. I seem to be
blocked by the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |