Hi,
Still struggling with my GUI exercise -
I have the following lines of code in a routine that is bound at <Key-Returnto
an instance of Entry :
self.disp.Amoun t_des = Label(self.disp , text = self.dis_string , fg =
'black', bg = 'yellow')
self.disp.Amoun t_des.grid(row = self.rownum, column=0, sticky = 'nesw')
self.disp.Amoun t = Label(self.disp , text = self.retstring, fg = 'black',
bg = 'green')
self.disp.Amoun t.grid(row = self.rownum, column=1, sticky = N+S+E+W)
The second call to the grid method fails as follows:
Exception in Tkinter callback
Traceback (most recent call last):
File "E:\PYTHON24\li b\lib-tk\Tkinter.py", line 1345, in __call__
return self.func(*args )
File "C:\WINDOWS\DES KTOP\Entry1.py" , line 243, in entryend
self.disp.Amoun t.grid(row = self.rownum, column=1, sticky = N+S+E+W)
TypeError: cannot concatenate 'str' and 'instance' objects
If I change the N+S+E+W to the 'nsew' form, it works no problem...
Weird - at other places in the program the form: sticky = N+S+E+W works without
a problem.
I found the 'nsew' form by trial and error...
self.disp is a window different from the current one - it is used to display a
record entry as it is built up field by field. - the code fragment above is what
inserts the description of the entry and the entered data in a row in the window
used for displaying, when the user hits the enter key.
Is this a bug, or am I still doing something wrong?
- Hendrik 3 2013
H J van Rooyen wrote:
Hi,
Still struggling with my GUI exercise -
I have the following lines of code in a routine that is bound at
<Key-Returnto an instance of Entry :
self.disp.Amoun t_des = Label(self.disp , text = self.dis_string , fg
=
'black', bg = 'yellow')
self.disp.Amoun t_des.grid(row = self.rownum, column=0, sticky =
'nesw')
self.disp.Amoun t = Label(self.disp , text = self.retstring, fg =
'black',
bg = 'green')
self.disp.Amoun t.grid(row = self.rownum, column=1, sticky =
N+S+E+W)
The second call to the grid method fails as follows:
Exception in Tkinter callback
Traceback (most recent call last):
File "E:\PYTHON24\li b\lib-tk\Tkinter.py", line 1345, in __call__
return self.func(*args )
File "C:\WINDOWS\DES KTOP\Entry1.py" , line 243, in entryend
self.disp.Amoun t.grid(row = self.rownum, column=1, sticky = N+S+E+W)
TypeError: cannot concatenate 'str' and 'instance' objects
If I change the N+S+E+W to the 'nsew' form, it works no problem...
Weird - at other places in the program the form: sticky = N+S+E+W works
without a problem.
I found the 'nsew' form by trial and error...
self.disp is a window different from the current one - it is used to
display a record entry as it is built up field by field. - the code
fragment above is what inserts the description of the entry and the
entered data in a row in the window used for displaying, when the user
hits the enter key.
Is this a bug, or am I still doing something wrong?
You have probably defined your own, say, E somewhere in your module:
E = ... # whatever
This can easily be fixed by using another name. But what you are really
doing wrong is using the
from Tkinter import *
star-import which drastically increases the likelihood of such name clashes.
I recommend using qualified names, abbreviated if you like:
import Tkinter as tk
.... tk.N + tk.S + tk.E + tk.W ... # a bit longer, but worth the effort
Of course this could still go wrong if you do
tk = 42
somewhere in your module...
Peter
On Tue, 01 Aug 2006 14:14:51 +0200, H J van Rooyen <ma**@microcorp .co.za
wrote:
Hi,
Still struggling with my GUI exercise -
I have the following lines of code in a routine that is bound at
<Key-Returnto
an instance of Entry :
self.disp.Amoun t_des = Label(self.disp , text = self.dis_string ,
fg =
'black', bg = 'yellow')
self.disp.Amoun t_des.grid(row = self.rownum, column=0, sticky =
'nesw')
self.disp.Amoun t = Label(self.disp , text = self.retstring, fg =
'black',
bg = 'green')
self.disp.Amoun t.grid(row = self.rownum, column=1, sticky =
N+S+E+W)
The second call to the grid method fails as follows:
Exception in Tkinter callback
Traceback (most recent call last):
File "E:\PYTHON24\li b\lib-tk\Tkinter.py", line 1345, in __call__
return self.func(*args )
File "C:\WINDOWS\DES KTOP\Entry1.py" , line 243, in entryend
self.disp.Amoun t.grid(row = self.rownum, column=1, sticky = N+S+E+W)
TypeError: cannot concatenate 'str' and 'instance' objects
If I change the N+S+E+W to the 'nsew' form, it works no problem...
Weird - at other places in the program the form: sticky = N+S+E+W works
without
a problem.
Simple: you have in this context a local or global variable named either
N, S, W or E, shadowing the constant defined in the Tkinter module. You
can find it by inserting a line like:
print repr(N), repr(S), repr(W), repr(E)
before your self.disp.Amoun t.grid in your code. This line should print:
'n' 's' 'w' 'e'
but I guess it won't...
The solutions are:
- Rename your variable.
- Always use the string form, i.e 'nswe'. This is the standard in native
tk. The N, S, W and E constants are just defined for convenience in
Tkinter.
- Do not use "from Tkinter import *" to import the module, but something
like "import Tkinter as tk", and then prefix all names in this module by
'tk.'. So your code above becomes:
self.disp.Amoun t = tk.Label(self.d isp, text = self.retstring, fg =
'black', bg = 'green')
self.disp.Amoun t.grid(row = self.rownum, column=1, sticky =
tk.N+tk.S+tk.E+ tk.W)
(I'm personnally not a big fan of this last solution, since I find it
clobbers the code a lot and decreases readability. But it's usually the
best way to avoid name clashes...)
[snip]
HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
"Peter Otten" <__*******@web. dewrote:
|H J van Rooyen wrote:
|
| Hi,
| >
| Still struggling with my GUI exercise -
| >
| I have the following lines of code in a routine that is bound at
| <Key-Returnto an instance of Entry :
| >
| self.disp.Amoun t_des = Label(self.disp , text = self.dis_string , fg
| =
| 'black', bg = 'yellow')
| self.disp.Amoun t_des.grid(row = self.rownum, column=0, sticky =
| 'nesw')
| >
| self.disp.Amoun t = Label(self.disp , text = self.retstring, fg =
| 'black',
| bg = 'green')
| self.disp.Amoun t.grid(row = self.rownum, column=1, sticky =
| N+S+E+W)
| >
| The second call to the grid method fails as follows:
| >
| Exception in Tkinter callback
| Traceback (most recent call last):
| File "E:\PYTHON24\li b\lib-tk\Tkinter.py", line 1345, in __call__
| return self.func(*args )
| File "C:\WINDOWS\DES KTOP\Entry1.py" , line 243, in entryend
| self.disp.Amoun t.grid(row = self.rownum, column=1, sticky = N+S+E+W)
| TypeError: cannot concatenate 'str' and 'instance' objects
| >
| If I change the N+S+E+W to the 'nsew' form, it works no problem...
| >
| Weird - at other places in the program the form: sticky = N+S+E+W works
| without a problem.
| I found the 'nsew' form by trial and error...
| >
| self.disp is a window different from the current one - it is used to
| display a record entry as it is built up field by field. - the code
| fragment above is what inserts the description of the entry and the
| entered data in a row in the window used for displaying, when the user
| hits the enter key.
| >
| Is this a bug, or am I still doing something wrong?
|
| You have probably defined your own, say, E somewhere in your module:
|
| E = ... # whatever
|
| This can easily be fixed by using another name. But what you are really
| doing wrong is using the
|
| from Tkinter import *
|
| star-import which drastically increases the likelihood of such name clashes.
| I recommend using qualified names, abbreviated if you like:
|
| import Tkinter as tk
|
| ... tk.N + tk.S + tk.E + tk.W ... # a bit longer, but worth the effort
|
| Of course this could still go wrong if you do
|
| tk = 42
|
| somewhere in your module...
|
| Peter
Well spotted that man! the offending line was:
def entryend(self,S ):
"""This gets done on carriage return"""
The 'S" is not actually used by me - it was added because the callback passes
Something back and I got an error earlier while I was still using pack...
*grin*
This also explains why it only happens here and not elsewhere...
Problem sorted - False alarm!
- Thanks This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Josh |
last post by:
Caution, newbie approaching...
I'm trying to come up with a very simple Tkinter test application that
consists of a window with a drop-down menu bar at the top and a grid
of colored rectangles filling the remainder of the window. Mind you,
this is a contrived test application to help me understand Tkinter and
Python, not an actual application yet. I've trivially subclassed
Tkinter.Canvas into ColorCanvas, added a bunch of ColorCanvases...
|
by: Richard Lewis |
last post by:
Hi there,
I've got a tree control in Tkinter (using the ESRF Tree module) but I
can't get it to layout how I want it.
I'd like to have it so that it streches north/south (anchored to the top
and bottom), is of a fixed width and is anchored to the left hand side.
Here's my code (its derived from one of the examples from the ESRF web
site):
|
by: aldonnelley |
last post by:
Hi all.
Just having a weird problem with tkinter. I'm trying to make a gui that
shows results from an image search, with a "forward" and "back" button
so the user can compare results from different pages. All that's
working fine...
The problem I'm having is that the images don't show onscreen the first
time the "first page" of results shows up. When I click the "search
again" button, and have more than the original results page to...
|
by: peter |
last post by:
I've come across a weird difference between the behaviour of the
Tkinter checkbox in Windows and Linux. The issue became apparent in
some code I wrote to display an image in a fixed size canvas widget. If
a checkbox was set then the image should be shrunk as necessary to fit
the canvas while if cleared it should appear full size with scrollbars
if necessary.
The code worked fine under Linux (where it was developed). But under
Windows,...
|
by: skanemupp |
last post by:
so my little calculator works perfectly now. just having some trouble
with the layout.
this whole tkinter-thing seems to be more tricky than it should be.
how can i make the 4 column of buttons have the same distance and
size between them as the other 3 columns?
and how can i make the top entry end where the 2nd row entry
ends(meaning the top entry will be longer)?
why are the 4th row split from the others? hard to fix the problems...
| |
by: viv1tyagi |
last post by:
Hi everyone ! ! !
I'm just a month old in the world of Python and trying to develop an
application using Tkinter in which a new window pops out on a
particular button press.The code for this new window is in
"AddKlas.py" file.
The problem is all the content of the new window is overwritten on
the previous window.
Below is the code of the two files
|
by: J-Burns |
last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in
programming itself... :P. Need some help here.
Problem 1:
How do I make something appear on 2 separate windows using Tkinter? By
this I mean that the format would be something like this:
You have Page1 : This has 2-3 buttons on it.
Clicking on each button opens up a new window respectively having
|
by: Guilherme Polo |
last post by:
On Wed, Sep 3, 2008 at 8:57 PM, Kevin McKinley <kem1723@yahoo.comwrote:
Come on.. "help on lines 384-403", that is not a good way to look for
help. You are supposed to post some minimal code that demonstrates the
problem.
Anyway, this demonstrates what you are getting (independent of python version):
import Tkinter
|
by: Francesco Bochicchio |
last post by:
Il Mon, 18 Aug 2008 12:15:10 +0100, dudeja.rajat ha scritto:
Uhm, I don't think you should use the grid manager to obtain a window
like that. The grid manager is for equally distributing widgets both
horizontally and vertically.
And I'm not sure that you can realize that window look with Tkinter.
You could get close by horizontally packing each widget row in a frame
and then vertically packing the frames in the window. But the look...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |