python >> TKINTER problem

by edlsoft » Fri, 18 Jul 2003 23:26:03 GMT

Have used TKINTER for years with Python v1.5.2 with great success. But
after installing verson 2.0 (and most recently 2.2.3) I have a problem
exiting widgets by clicking on the exit button (x on upper right ---
)---the system hangs. It's driving me nuts. Can some kind soul
indicate what PATH statement they're using which deals with
TCL/TK, etc?

Burt Leavenworth.


python >> Tkinter Problem

by Maboroshi » Sun, 24 Oct 2004 06:02:05 GMT


Why when I use the sticky command with the grid layout manager won't my
Listbox expand it stays in the center maybe I am missing something but
from every tutorial I see it says to do it this way

I am running Python2.3.4 on winxp I haven't tried it on linux yet

Any Ideas are appreciated

Let me know if I am not being clear enough

Cheers

Andrew


from Tkinter import *


class App(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
self.createWidgets()

def createWidgets(self):
self.listbox = Listbox(self)
# RIGHT HERE THIS WON'T EXPAND TO FILL
self.listbox.grid(row=0, column=0, rowspan=3, sticky=N+E+S+W)

self.connect = Button(self, text="Connect")
self.connect.grid(row=0, column=1)
self.execute = Button(self, text="Execute")
self.execute.grid(row=1, column=1)
self.disconnect = Button(self, text="Disconnect")
self.disconnect.grid(row=2, column=1)

self.entry = Entry(self)
self.entry.grid(row=3, column=0, columnspan=2, sticky=E+W)


app = App()
app.master.title("MySQL DB Project")
app.master.minsize(400, 300)
app.mainloop()



python >> Tkinter Problem

by Peter Otten » Sun, 24 Oct 2004 18:36:33 GMT





Remove


This means you have an additional grid containing a single control (the
Frame). Use a packer instead and make sure it consumes any extra space:

self.pack(fill=BOTH, expand=True)


You can configure the cell (0, 0) to consume any extra space:

self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)


The Entry and Listbox widgets should grow now as expected. To distribute the
Buttons smoothly, you can either set the weight of columns 1 and 2 or put
all three of them in an extra Frame (which I would prefer).

Peter


Tkinter Problem

by Maboroshi » Mon, 25 Oct 2004 01:31:33 GMT

Hey Thank you works now

Cheers

Andrew


Tkinter problem

by dale cooper » Mon, 31 Oct 2005 20:26:20 GMT

Hi everybody!
I've recently installed python2.4.2 on Fedora 4 (from downloaded
sources), but it appeared, that I can't use Tkinter module:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.4/lib-tk/Tkinter.py", line 38, in ?
import _tkinter # If this fails your Python may not be configured
for Tk
ImportError: libBLT24.so: cannot open shared object file: No such file
or directory

I tried the solution given in README file for RH9 (./configure
--enable-unicode=ucs4) despite they wrote the newer wersion didn't need
this hack. This is what I had after make instruction:

INFO: Can't locate Tcl/Tk libs and/or headers
*** WARNING: renaming "array" since importing it failed:
build/lib.linux-i686-2.4/array.so: undefined symbol:
PyUnicodeUCS2_FromUnicode
*** WARNING: renaming "_testcapi" since importing it failed:
build/lib.linux-i686-2.4/_testcapi.so: undefined symbol:
PyUnicodeUCS2_Decode
*** WARNING: renaming "unicodedata" since importing it failed:
build/lib.linux-i686-2.4/unicodedata.so: undefined symbol:
PyUnicodeUCS2_FromUnicode
*** WARNING: renaming "_locale" since importing it failed:
build/lib.linux-i686-2.4/_locale.so: undefined symbol:
PyUnicodeUCS2_AsWideChar
*** WARNING: renaming "cPickle" since importing it failed:
build/lib.linux-i686-2.4/cPickle.so: undefined symbol:
PyUnicodeUCS2_AsUTF8String
*** WARNING: renaming "pyexpat" since importing it failed:
build/lib.linux-i686-2.4/pyexpat.so: undefined symbol:
PyUnicodeUCS2_DecodeUTF8
*** WARNING: renaming "_multibytecodec" since importing it failed:
build/lib.linux-i686-2.4/_multibytecodec.so: undefined symbol:
PyUnicodeUCS2_FromUnicode
running build_scripts

It seems that --enable-unicode=ucs4 wasn't the right way. I tried
another hack: ./configure --enable-shared, but it still couldn't locate
Tcl/Tk libs and/or headers. Then I installed RPMs:

[root@localhost Python-2.4.2]# rpm -q tk
tk-8.4.9-3
[root@localhost Python-2.4.2]# rpm -q tcl
tcl-8.4.9-3
[root@localhost Python-2.4.2]# rpm -q tkinter
tkinter-2.4.1-2

and tried to do the hacks above, but it still could'nt find these libs.
What can I do?



Tkinter problem

by Fredrik Lundh » Mon, 31 Oct 2005 22:36:29 GMT





this seems to indicate that the build process picked up the Tk BLT extension [1],
but that you haven't installed that extension properly.

</F>

1) http://sourceforge.net/projects/blt/





Tkinter problem

by dale cooper » Tue, 01 Nov 2005 07:17:05 GMT

Thanks, but I've got another question:

can't find Tcl configuration script "tclConfig.sh"

This is what I received trying to install TkBLT. What is tclConfig.sh?
I did installed tcl/tk 8.4.9-3 as I mentioned before, I tried to find
this file, but I don't have it in my filesystem. How to get it?



Tkinter problem

by jepler » Tue, 01 Nov 2005 09:26:34 GMT




This file comes from the following package:
$ rpm -qf /usr/lib*/tclConfig.sh
tcl-devel-8.4.9-3

Fedora generally splits packages which are libraries into "foo" and "foo-devel"
(and maybe others).

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDZsRJJd01MZaTXX0RAuTCAKCn6VKuuzJ9h6+D3RHUfyZUWK10TQCfeF56
m27PiTggLSs6hXRufx1Sq3A=
=lH+/
-----END PGP SIGNATURE-----



Tkinter problem

by dale cooper » Wed, 02 Nov 2005 05:01:35 GMT

Thanks!
At this moment I can see the first python generated Tk window on my
screen. It's great ;-)))



TKinter problem

by C D Wood » Tue, 21 Mar 2006 20:03:04 GMT

To whom this may concern,
Below is the source code, which

demonstrates a
problem I am having making a GUI for my python project work.
'table.txt'
is a file that is read from the same folder.

My code writes to a text file 'table.txt', and 'table.txt' is displayed
in
the GUI. The user can generate new data at the click of a button
which re-writes 'table.txt', but I can only add the new table to the
GUI
window rather than 'update' the existing one.

Any assistance would be much appreciated,

Regards,
Christian Wood.
Part III Aerospace Engineering
University of Southampton, UK.

##################################################################
from Tkinter import *

#Tkinter User Interface
class MoC:
def __init__(self, master):
frame = Frame(master, width=600, height=800, bd=1)
frame.pack()

#Button frame
iframe4 = Frame(frame, bd=2, relief=SUNKEN)
#Using this button below, I want to update the text box in iframe5.
Button(iframe4, text='Display table.txt',
command=self.DisplayUpdate).pack(side=LEFT, padx=5)
Button(iframe4, text='Quit', command=self.quit).pack(side=LEFT,
padx=5)
iframe4.pack(expand=1, fill=X, pady=10, padx=5)

#Text box frame
iframe5 = Frame(frame, bd=2, relief=SUNKEN)
text=Text(iframe5, height=10, width =70)
fd = open('table.txt') #table.txt must be in the same folder
lines = fd.read()
fd.close()
text.insert(END, lines)
text.pack(side=LEFT, fill=X, padx=5)
sb = Scrollbar(iframe5, orient=VERTICAL, command=text.yview)
sb.pack(side=RIGHT, fill=Y)
text.configure(yscrollcommand=sb.set)
iframe5.pack(expand=1, fill=X, pady=10, padx=5)

#Command definitions
def quit(self):
root.destroy()

def DisplayUpdate(self): #The command definition used to update the
display.
#Could I insert a line here to remove the existing frame/text
box first? <<<<<=====
iframe5 = Frame(root, bd=2, relief=SUNKEN)
text = Text(iframe5, height=10, width =70)
fd = open('table.txt')
lines = fd.read()
fd.close()
text.insert(END, lines)
text.pack(side=LEFT, fill=X, padx=5)
sb = Scrollbar(iframe5, orient=VERTICAL, command=text.yview)
sb.pack(side=RIGHT, fill=Y)
text.configure(yscrollcommand=sb.set)
iframe5.pack(expand=1, fill=X, pady=10, padx=5)

root = Tk()
root.option_add('*font', ('arial', 10))
all = MoC(root)
root.title('2D Method of Characteristics')
root.update
root.mainloop()



TKinter problem

by ezd » Tue, 21 Mar 2006 23:27:16 GMT

D Wood wrote:

What you want probably looks like this:

from Tkinter import *
class MoC:
def __init__(self, master):
frame = Frame(master, width=600, height=800, bd=1)
frame.pack()
iframe4 = Frame(frame, bd=2, relief=SUNKEN)
Button(iframe4, text='Display table.txt',
command=self.DisplayUpdate).pack(side=LEFT, padx=5)
Button(iframe4, text='Quit',
command=self._quit).pack(side=LEFT, padx=5)
iframe4.pack(expand=1, fill=X, pady=10, padx=5)
iframe5 = Frame(frame, bd=2, relief=SUNKEN)
self.text=Text(iframe5, height=10, width =70)
# read the file in the update function; create Text & Scrollbar
only once
self.text.pack(side=LEFT, fill=X, padx=5)
sb = Scrollbar(iframe5, orient=VERTICAL,
command=self.text.yview)
sb.pack(side=RIGHT, fill=Y)
self.text.configure(yscrollcommand=sb.set)
iframe5.pack(expand=1, fill=X, pady=10, padx=5)
self.DisplayUpdate()
def _quit(self): # quit is a keyword in python 2.4 IDE
root.destroy()
def DisplayUpdate(self):
fd = open('table.txt')
lines = fd.read()
fd.close()
self.text.config(state=NORMAL)
self.text.delete(1.0, END)
self.text.insert(END, lines)
self.text.config(state=DISABLED)
# previous 4 lines are to make the text READONLY, see more in:
#
http://www.pythonware.com/library/tkinter/introduction/x8309-patterns.htm
root = Tk()
root.option_add('*font', ('arial', 10))
all = MoC(root)
root.title('2D Method of Characteristics')
root.update
root.mainloop()

ezd



Tkinter problem

by Jim Anderson » Sat, 08 Jul 2006 05:55:28 GMT


I'm running Kubuntu a derivative of Debian Linux. I'm using
Python 2.4 and tcl/tk 8.4. I'm running Tkinter programs and
they were running about a month ago. When I tried them again
yesterday, I got the following message:

> python ~/prog/python/iodef/iodef.py
> Traceback (most recent call last):
> File "/home/jja/prog/python/iodef/iodef.py", line 10, in ?
> import pkgview
> File "/home/jja/prog/python/iodef/lib/pkgview.py", line 3, in ?
> from Tkinter import *
> File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 38, in ?
> import _tkinter # If this fails your Python may not be configured
> for Tk
> ImportError: /usr/lib/python2.4/lib-dynload/_tkinter.so: cannot open
> > shared object file: No such file or directory

My environment varibles, like PTYHONPATH and TK_LIBRIARY all look
correct and the tcl/tk and python librarys are all still in place.
There is a file '/usr/lib/python2.4/lib-dynload/_tkinter.so'. I'm
not sure if this is the file not being found, but that is what is
sounds like.

I did a search on this on the web and got some hits, but none of them
provide a solution to my problem.

Can anyone help with this problem?

Jim Anderson


Tkinter problem

by Simon Forman » Sat, 08 Jul 2006 09:36:50 GMT




Just an idea, but if you're sure that
/usr/lib/python2.4/lib-dynload/_tkinter.so exists, check it's
permissions and the permissions of /usr/lib/python2.4/lib-dynload/

HTH,
~Simon



Tkinter problem

by Nick Craig-Wood » Sun, 09 Jul 2006 13:32:17 GMT




Also run ldd on it - you could be missing a library

eg

$ ldd /usr/lib/python2.4/lib-dynload/_tkinter.so
linux-gate.so.1 => (0xffffe000)
libBLT.2.4.so.8.4 => /usr/lib/libBLT.2.4.so.8.4 (0xb7e80000)
libtk8.4.so.0 => /usr/lib/libtk8.4.so.0 (0xb7dab000)
libtcl8.4.so.0 => /usr/lib/libtcl8.4.so.0 (0xb7cfc000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0xb7c31000)
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7c1e000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7ae6000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7ac0000)
libnsl.so.1 => /lib/tls/i686/cmov/libnsl.so.1 (0xb7aa9000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7aa5000)
/lib/ld-linux.so.2 (0x80000000)

If there are any missing things then you need to re-install those
packages.

--
Nick Craig-Wood < XXXX@XXXXX.COM > -- http://www.craig-wood.com/nick


tkinter problem

by Paul Simon » Thu, 09 Jul 2009 07:18:02 GMT

I have the "tkinter" problem and need some assistance to straighten it out.
From the web page " http://wiki.python.org/moin/TkInter " I tested as in "step
1" and cannot import "_tkinter." I do not have that file on my computer, but
do have tkinter.py in /usr/local/lib/python2.6/lib-tk. as well as the
directories /usr/lib/tk8.5 and /usr/lib/tcl8.5.
This python stuff is great, but the documentation frequently
feels like it is just a bit out of my grasp. I realize that all of this is
free but I understand the instructions on the web page to repair only to the
point of confusion. I'm not an expert. How do I modify my python
configuration? Is there a file that needs to be edited? Which setup.py file
do I use? Make? or python setup.py build and python setup.py install?
Thanks. I appreciate your help.
Paul Simon




Similar Threads

1. Suggestions wanted on Tkinter problem

2. Simple Tkinter problem

Hi all,

I'm trying to write a GUI that will put up multiple widgets in
succession. My problem is that each widget also contains the previous
widgets when they pop up. How do I reinitialize the widget each time so
that it doesn't contain earlier ones? Actually, another question I have
is, is there a way to set python so that it will assume any undefined
variable is 0 or ''? That is, I have several statements like "If k > 0
then so and so" and I would like it to assume k=0 unless I tell it
otherwise. I've just been defining k=0 at the start of the program but
it seems there should be a better way.

Greg

3. Tkinter - problem closing window

4. Thread Tkinter problem

Hi all,

I am using thread and tkinter to write some simple programs and
solidify my understanding of Python thread/GUI programing. The scheme
is thread + queue + GUI. One child thread (gen_board_thread) generate
board and insert data into queue infinitely. Meanwhile, the main
thread canvas widget get the board data from queue.

I assume the program will run forever if don't close them explicitly,
but the fact is contrary to my understanding. It seems the child
thread insert data till queue is full, then the main thread eat the
data till the queue is empty, and the main thread starve(when timeout
option is set) and die. So the two thread work like two function call,
but not two thread!

Is this situation caused by deadlock(I guess main thread has higher
priority)? Or how can I know whether the child thread is still alive?
Ultimately, how to solve the problem?

The code are attached.
Any suggestion will be appreciated :-)
Best regards,
Davy

//---------Code below---------------
from Tkinter import *
import thread
import Queue
##import time

x = 3 ## vertical
y = 5 ## horizontal
block_width = 10
block_height = 10
canvas_width = x * block_width
canvas_height = y * block_height

data_queue = Queue.Queue(20)

board_1 = [[1,0,1],
         [0,1,1],
         [1,0,0],
         [0,0,1],
         [0,1,0]]

board_2 = [[0,1,0],
         [1,0,0],
         [0,1,1],
         [1,1,0],
         [1,0,1]]

def gen_board_thread():
    ## Problem: the thread seems to be deadlock or killed or postponed
after execution was taken over by main thread draw_canvas_loop()
    print 'enter here'
    gen_flip = 1
    while(data_queue.full() == False):
        ##print '???'
        ##time.sleep(0.1)
        if (gen_flip == 1):
            gen_flip = 0
            data = board_1
        else:
            gen_flip = 1
            data = board_2
        data_queue.put(data)
        print 'put', data_queue.qsize()

def create_canvas(root,canvas_width,canvas_height,):
    canvas = Canvas(root, width=canvas_width, height=canvas_height,
bg='white')
    canvas.pack(expand=YES)
    return canvas

def draw_canvas_loop(canvas_b):
    board = data_queue.get(block = True, timeout=1)
    print 'get', data_queue.qsize()
    draw_canvas(board, canvas_b, x, y, block_width, block_height)
    canvas_b.after(300, lambda:draw_canvas_loop(canvas_b))


def draw_canvas(board, canvas_b, x, y, block_width, block_height):
    ##canvas_b.after(3000)
    ##time.sleep(3)
    for j in range(y):
        for i in range(x):
            if board[j][i] == 1:
                color = 'black'
            else:
                color = 'white'
            start_x = block_width * i
            start_y = block_height * j
            end_x = start_x + block_width
            end_y = start_y + block_height
            canvas_b.create_rectangle
(start_x,start_y,end_x,end_y,fill=color)

if __name__ == '__main__':
    root = Tk()
    root.title('Tetris')
    canvas = create_canvas(root,canvas_width,canvas_height)
    thread.start_new(gen_board_thread,())
    draw_canvas_loop(canvas)
    mainloop()

5. Windows / Tkinter - problem with grid - not able to place widgets at desired places

6. Socket and Tkinter Problem

Hallo,

I have a problem with Tkinter and the module socket. In a console-window
everything works fine, but in a Tkinter-window I can no more use the
widgets. I found some other mails with this problem, but no solution (I
understand really :-)

Here is my code:
-----------------------------------------------
import win32ui, dde, string, time, os, sys, shutil
from socket import *
from Tkinter import *
from tkFileDialog import *
from tkMessageBox import *
import win32com.client

def sockelserver():
    while 1:
        HOST = 'localhost'
        PORT = 8578
        s = socket(AF_INET, SOCK_STREAM)
        s.bind((HOST,PORT))
        s.listen(1)
        log("wait...")
        hs,addr=s.accept()
        log("connected with: "+str(addr))
        while 1:
            data=hs.recv(1024)
            if not data:break
            if data=="'exit'":break
            erg='hallo'
#     erg=datawash(data)
            log("reiceved: "+data)
            hs.send(erg)
        hs.close()
        if data=="'exit'":break

def log(nachricht):
    anzahl_lines=string.count(logtext.get(1.0,END),'\n')
    if anzahl_lines>2000:logtext.delete(0.0,2.0)
    logtext.insert(END,time.asctime()+'\t'+nachricht+'\n')
    logtext.see(END)
    root.update()

root = Tk()
midframe =Frame(root, borderwidth=2, relief=GROOVE)
Label(midframe,text='Logg-Fenster').pack(side=TOP)
scrollbar = Scrollbar(midframe, orient=VERTICAL)
scrollbar.pack(fill=Y, side=RIGHT)
logtext = Text(midframe)
logtext.pack()
logtext.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=logtext.yview)
midframe.pack(padx=2, pady=2)
botframe = Frame(root)
botframe.pack(padx=2, pady=2)
Button(botframe, text='Start',
command=sockelserver).pack(side=LEFT,padx=2,pady=2)
Button(botframe, text='Exit',
command=root.destroy).pack(side=LEFT,padx=2,pady=2)
root.title('DDE-Server')
root.mainloop()

--------------------------------------
The function is easy. I want to start a server that waits for connection and
answer with an result. The communication-protocol is printed out in a
Text-window.

Please help me out :-)
Cheers Thomas


7. Python 2.3.2 / Tkinter Problem

8. Tkinter Problems on MAC OS 10.3.9 & python2.5

Hello folks,

my name is Thomas, and I am new to this newsgroup. So first I want to
say hello. :-)

...done!

Now, I have a problem concerning my new python2.5 install. With
python2.3 and 2.4, Tkinter was no problem.

Now, when I try to import it, the folowing happens:

iPimpG4:~/Python-Dev/examples profipimp$ python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py",
line 38, in <module>
    import _tkinter # If this fails your Python may not be configured
for Tk
ImportError: dlcompat: dyld:
/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python
can't open library: /Library/Frameworks/Tk.framework/Versions/8.4/Tk
(No such file or directory, errno = 2)