Computer locks up when running valid stand alone Tkinter file.
faulkner
faulkner612 at comcast.net
Wed Oct 25 23:05:49 EDT 2006
> 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()
More information about the Python-list
mailing list