Computer locks up when running valid stand alone Tkinter file.

J

jim-on-linux

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()
 
F

faulkner

But, when I call it from another module it locks
methinks this "other module" has the answer.
 
J

jim-on-linux

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top