py help,
The file below will run as a stand alone file.
It works fine as it is.
But, when I call it from another module it locks
my computer, The off switch is the only
salvation.
This module when run as a stand alone, it will
open a jpeg image and add a vertical and
horizontal scrollbar to the canvass.
That's all it does.
Replace the img9.jpg file with one of your own,
put the image in the current working dir., and
run.
If you think you can help, I would appreciate it.
jim-on-linux
############################################
#!/usr/bin/env python
"""
#############################################
import Tkinter as Tk
Do not do
( from Tkinter import * )
because of name space conflict with
Image.open
##############################################
#### below imports Image and ImageTk are from
#### Imaging-1.1.5, PIL in Python
"""
import Image
import ImageTk
import Tkinter as Tk
import os
vpath = os.getcwd()+os.sep+'img9.jpg'
class Kshow_0 :
def __init__(self ) :
self.Fimgshow0()
def Fimgshow0(self ) :
window = Tk.Tk() # used for stamd alone
# window = Tk.Toplevel()
# Above Toplevel call used when running
# from another file
window.title(' Image Location '+vpath )
window.protocol('WM_DELETE_WINDOW',
window.destroy)
vcanvas = Tk.Canvas(window, width = 375,
height=375,
borderwidth = 1, bg=
'white')
sbarY=Tk.Scrollbar()
sbarX = Tk.Scrollbar( orient='horizontal')
sbarY.config(command= vcanvas.yview)
sbarX.config(command= vcanvas.xview)
vcanvas.config(yscrollcommand=sbarY.set)
vcanvas.config(xscrollcommand=sbarX.set)
sbarY.pack(side='right', fill='y')
sbarX.pack(side='bottom', fill='x')
vcanvas.pack(expand='yes', fill='both')
im= Image.open( vpath)
tkim = ImageTk.PhotoImage(im)
imgW = tkim.width()
print imgW, '## imgW, jpg 58\n'
imgH = tkim.height()
print imgH, '## imgH, jpg 61\n'
# Draw the image on the canvas
vcanvas.create_image(0, 0, image=tkim,
anchor = 'nw' )
vcanvas.config(scrollregion= (0, 0, imgW,
imgH))
window.mainloop ()
if __name__ == '__main__' :
Kshow_0() 2 2122
But, when I call it from another module it locks
methinks this "other module" has the answer.
jim-on-linux wrote:
py help,
The file below will run as a stand alone file.
It works fine as it is.
But, when I call it from another module it locks
my computer, The off switch is the only
salvation.
This module when run as a stand alone, it will
open a jpeg image and add a vertical and
horizontal scrollbar to the canvass.
That's all it does.
Replace the img9.jpg file with one of your own,
put the image in the current working dir., and
run.
If you think you can help, I would appreciate it.
jim-on-linux
############################################
#!/usr/bin/env python
"""
#############################################
import Tkinter as Tk
Do not do
( from Tkinter import * )
because of name space conflict with
Image.open
##############################################
#### below imports Image and ImageTk are from
#### Imaging-1.1.5, PIL in Python
"""
import Image
import ImageTk
import Tkinter as Tk
import os
vpath = os.getcwd()+os.sep+'img9.jpg'
class Kshow_0 :
def __init__(self ) :
self.Fimgshow0()
def Fimgshow0(self ) :
window = Tk.Tk() # used for stamd alone
# window = Tk.Toplevel()
# Above Toplevel call used when running
# from another file
window.title(' Image Location '+vpath )
window.protocol('WM_DELETE_WINDOW',
window.destroy)
vcanvas = Tk.Canvas(window, width = 375,
height=375,
borderwidth = 1, bg=
'white')
sbarY=Tk.Scrollbar()
sbarX = Tk.Scrollbar( orient='horizontal')
sbarY.config(command= vcanvas.yview)
sbarX.config(command= vcanvas.xview)
vcanvas.config(yscrollcommand=sbarY.set)
vcanvas.config(xscrollcommand=sbarX.set)
sbarY.pack(side='right', fill='y')
sbarX.pack(side='bottom', fill='x')
vcanvas.pack(expand='yes', fill='both')
im= Image.open( vpath)
tkim = ImageTk.PhotoImage(im)
imgW = tkim.width()
print imgW, '## imgW, jpg 58\n'
imgH = tkim.height()
print imgH, '## imgH, jpg 61\n'
# Draw the image on the canvas
vcanvas.create_image(0, 0, image=tkim,
anchor = 'nw' )
vcanvas.config(scrollregion= (0, 0, imgW,
imgH))
window.mainloop ()
if __name__ == '__main__' :
Kshow_0()
Thanks for responding,
For those who care.
The solution to the problem was;
First, I did not give a parent to the Yview
scrollbar.
Next, I used the pack geometry for this class and
everything else is grid geometry.
When run stand alone it ran fine because the Yview
scrollbar attached itself to the default parent,
but when run from another module, it locked up.
The difficulty is really in the fact that
scrollbar Yview without a parent tried to attach
itself to the root Tk, already built and running
with grid geometry.
Pack and grid in the same Frame don't get along
(computer lockup).
Give Yview a parent, problem solved.
Changed pack to grid anyway.
jim-on-linux http://www.inqvista.com
On Wednesday 25 October 2006 23:05, you wrote:
But, when I call it from another module it
locks
methinks this "other module" has the answer.
jim-on-linux wrote:
py help,
The file below will run as a stand alone
file. It works fine as it is.
But, when I call it from another module it
locks my computer, The off switch is the only
salvation.
This module when run as a stand alone, it
will open a jpeg image and add a vertical and
horizontal scrollbar to the canvass. That's
all it does.
Replace the img9.jpg file with one of your
own, put the image in the current working
dir., and run.
If you think you can help, I would appreciate
it.
jim-on-linux
############################################
#!/usr/bin/env python
"""
#############################################
import Tkinter as Tk
Do not do
( from Tkinter import * )
because of name space conflict with
Image.open
#############################################
#
#### below imports Image and ImageTk are
from #### Imaging-1.1.5, PIL in Python
"""
import Image
import ImageTk
import Tkinter as Tk
import os
vpath = os.getcwd()+os.sep+'img9.jpg'
class Kshow_0 :
def __init__(self ) :
self.Fimgshow0()
def Fimgshow0(self ) :
window = Tk.Tk() # used for stamd
alone
# window = Tk.Toplevel()
# Above Toplevel call used when
running # from another file
window.title(' Image Location '+vpath
) window.protocol('WM_DELETE_WINDOW',
window.destroy)
vcanvas = Tk.Canvas(window, width =
375, height=375, borderwidth = 1, bg=
'white')
sbarY=Tk.Scrollbar()
sbarX = Tk.Scrollbar(
orient='horizontal') sbarY.config(command=
vcanvas.yview) sbarX.config(command=
vcanvas.xview)
vcanvas.config(yscrollcommand=sbarY.set)
vcanvas.config(xscrollcommand=sbarX.set)
sbarY.pack(side='right', fill='y')
sbarX.pack(side='bottom', fill='x')
vcanvas.pack(expand='yes',
fill='both')
im= Image.open( vpath)
tkim = ImageTk.PhotoImage(im)
imgW = tkim.width()
print imgW, '## imgW, jpg 58\n'
imgH = tkim.height()
print imgH, '## imgH, jpg 61\n'
# Draw the image on the canvas
vcanvas.create_image(0, 0,
image=tkim, anchor = 'nw' )
vcanvas.config(scrollregion= (0, 0,
imgW, imgH)) window.mainloop ()
if __name__ == '__main__' :
Kshow_0()
This discussion thread is closed Replies have been disabled for this discussion. Similar topics
1 post
views
Thread by Marc |
last post: by
|
3 posts
views
Thread by Rob Mayo |
last post: by
|
4 posts
views
Thread by a8736d53 |
last post: by
|
669 posts
views
Thread by Xah Lee |
last post: by
| |
13 posts
views
Thread by Edwin Smith |
last post: by
|
7 posts
views
Thread by Jan |
last post: by
|
3 posts
views
Thread by Vik Rubenfeld |
last post: by
|
17 posts
views
Thread by henry |
last post: by
| | | | | | | | | | |