hi all
i recently wrote a script that implements a puzzle. the interface
mostly consists of a bunch of colored disks on a tkinter canvas. the
problem is that the disks change their colors in ways other than the
way they're supposed to. it certainly isn't just a bug in my script,
since i can sometimes change the color of certain disks just by taking
focus off of the window and then bringing it back again! does this
sound like some known bug in tkinter? and if so, is there a recommended
way of working around it? if it matters, i'm using python 2.3 under
windows 95. any advice will be much appreciated.
peace 5 2186
Sean McIlroy wrote: hi all
i recently wrote a script that implements a puzzle. the interface mostly consists of a bunch of colored disks on a tkinter canvas. the problem is that the disks change their colors in ways other than the way they're supposed to. it certainly isn't just a bug in my script, since i can sometimes change the color of certain disks just by taking focus off of the window and then bringing it back again! does this sound like some known bug in tkinter? and if so, is there a recommended way of working around it? if it matters, i'm using python 2.3 under windows 95. any advice will be much appreciated.
It sounds to me much more like a bug in your script, to me at least.
Change of focus generates windowing events in much the same way as
clicking a button or hitting a key does, so I don't understand why you
think that "just [by] taking the focus off the window and bringing it
back again" shouldn't change anything.
For more specific insights we'd need to see some code, but sometimes
just changing your own focus from "Tkinter has a bug" to "my code has a
bug" is enough to help one find out what the problem really is. If you
have a soft toy I'd recommend you sit it down somewhere and explain to
it in great detail exactly why it can't be a bug in your program. You
may find you discover the error with no further assistance.
If not, fire the toy and ask again :-)
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
Steve Holden wrote: Sean McIlroy wrote:
hi all
i recently wrote a script that implements a puzzle. the interface mostly consists of a bunch of colored disks on a tkinter canvas. the problem is that the disks change their colors in ways other than the way they're supposed to. it certainly isn't just a bug in my script, since i can sometimes change the color of certain disks just by taking focus off of the window and then bringing it back again! does this sound like some known bug in tkinter? and if so, is there a recommended way of working around it? if it matters, i'm using python 2.3 under windows 95. any advice will be much appreciated. It sounds to me much more like a bug in your script, to me at least. Change of focus generates windowing events in much the same way as clicking a button or hitting a key does, so I don't understand why you think that "just [by] taking the focus off the window and bringing it back again" shouldn't change anything.
For more specific insights we'd need to see some code, but sometimes just changing your own focus from "Tkinter has a bug" to "my code has a bug" is enough to help one find out what the problem really is. If you have a soft toy I'd recommend you sit it down somewhere and explain to it in great detail exactly why it can't be a bug in your program. You may find you discover the error with no further assistance.
If not, fire the toy and ask again :-)
regards Steve
To add to Steve's humorous perosonificatio us techniques. You should
probably check that you aren't inadvertently using some sort of object
id or window handle as a color value. As long as the object you use
returns an integer you won't get an error message, but instead get
different colors when the canvas object is updated. Like when changing
the focus.
Another place to look is where you may be adding or converting rgb color
values.
This function convert decimal rgb values to a hex rgb string that
tkinter expects.
def rgb(red, green, blue):
""" Convert RGB value of 0 to 255 to
hex Tkinter color string.
"""
return '#%02x%02x%02x' % (red, green, blue)
Cheers,
Ron
i'm using the canned colors ("pink", "orange", etc). should i try
changing to explicit color specifications to see if that makes a
difference? i'm not sure what the other guy meant by a "soft toy", but
i take it the idea is to try and construct a correctness proof for the
script, and see what keeps it (the proof) from working. it's a sound
idea, of course, but the script is pretty darn straightforward , as you
can see (below). anyway, i'll let you know how it turns out.
peace
############### #############
green = 'green'
orange = 'orange'
pink = 'pink'
yellow = 'yellow'
red = 'red'
blue = 'blue'
fb = 'frontback'
ud = 'updown'
lr = 'leftright'
def select(x,a,b): return b[a.index(x)]
def frontback(orien tation): return
select(orientat ion,[fb,ud,lr],[fb,lr,ud])
def updown(orientat ion): return
select(orientat ion,[fb,ud,lr],[lr,ud,fb])
def leftright(orien tation): return
select(orientat ion,[fb,ud,lr],[ud,fb,lr])
class cell:
def __init__(self, circlecolor, pointercolor, orientation,
coordinates):
self.circlecolo r = circlecolor
self.pointercol or = pointercolor
self.orientatio n = orientation
self.coordinate s = coordinates
def endpoint(self):
a,b = self.coordinate s
if self.orientatio n==fb:
if abs(a)==1: return [2*a,2*b]
if abs(a)==2: return [a/2,b/2]
if self.orientatio n==ud: return [+a,-b]
if self.orientatio n==lr: return [-a,+b]
class cube:
def __init__(self):
self.ful = cell(green, blue, fb, [-2,+2])
self.fur = cell(orange, blue, fb, [+2,+2])
self.fdl = cell(pink, blue, fb, [-2,-2])
self.fdr = cell(yellow, blue, fb, [+2,-2])
self.bul = cell(green, red, fb, [-1,+1])
self.bur = cell(orange, red, fb, [+1,+1])
self.bdl = cell(pink, red, fb, [-1,-1])
self.bdr = cell(yellow, red, fb, [+1,-1])
self.cells =
[self.ful,self.f ur,self.fdl,sel f.fdr,self.bul, self.bur,self.b dl,self.bdr]
def redraw(self,*ce lls):
for x in cells:
A = x.coordinates
B = x.endpoint()
erase(*A)
drawpointer(col or=x.pointercol or,*(A+B))
drawcircle(colo r=x.circlecolor ,*A)
def display(self):
self.redraw(*se lf.cells)
def cycle(self,a,b, c,d,funct):
x = d.circlecolor
y = d.pointercolor
z = funct(d.orienta tion)
d.circlecolor = c.circlecolor
d.pointercolor = c.pointercolor
d.orientation = funct(c.orienta tion)
c.circlecolor = b.circlecolor
c.pointercolor = b.pointercolor
c.orientation = funct(b.orienta tion)
b.circlecolor = a.circlecolor
b.pointercolor = a.pointercolor
b.orientation = funct(a.orienta tion)
a.circlecolor = x
a.pointercolor = y
a.orientation = z
rubik = cube()
def F1_():
rubik.cycle(rub ik.ful,rubik.fu r,rubik.fdr,rub ik.fdl,frontbac k)
def F2_():
rubik.cycle(rub ik.fdl,rubik.fd r,rubik.fur,rub ik.ful,frontbac k)
def B1_():
rubik.cycle(rub ik.bdl,rubik.bd r,rubik.bur,rub ik.bul,frontbac k)
def B2_():
rubik.cycle(rub ik.bul,rubik.bu r,rubik.bdr,rub ik.bdl,frontbac k)
def U1_(): rubik.cycle(rub ik.bul,rubik.bu r,rubik.fur,rub ik.ful,updown)
def U2_(): rubik.cycle(rub ik.ful,rubik.fu r,rubik.bur,rub ik.bul,updown)
def D1_(): rubik.cycle(rub ik.bdl,rubik.bd r,rubik.fdr,rub ik.fdl,updown)
def D2_(): rubik.cycle(rub ik.fdl,rubik.fd r,rubik.bdr,rub ik.bdl,updown)
def L1_():
rubik.cycle(rub ik.ful,rubik.bu l,rubik.bdl,rub ik.fdl,leftrigh t)
def L2_():
rubik.cycle(rub ik.fdl,rubik.bd l,rubik.bul,rub ik.ful,leftrigh t)
def R1_():
rubik.cycle(rub ik.fur,rubik.bu r,rubik.bdr,rub ik.fdr,leftrigh t)
def R2_():
rubik.cycle(rub ik.fdr,rubik.bd r,rubik.bur,rub ik.fur,leftrigh t)
def F1(): F1_(); rubik.redraw(ru bik.ful,rubik.f ur,rubik.fdr,ru bik.fdl)
def F2(): F2_(); rubik.redraw(ru bik.fdl,rubik.f dr,rubik.fur,ru bik.ful)
def B1(): B1_(); rubik.redraw(ru bik.bdl,rubik.b dr,rubik.bur,ru bik.bul)
def B2(): B2_(); rubik.redraw(ru bik.bul,rubik.b ur,rubik.bdr,ru bik.bdl)
def U1(): U1_(); rubik.redraw(ru bik.bul,rubik.b ur,rubik.fur,ru bik.ful)
def U2(): U2_(); rubik.redraw(ru bik.ful,rubik.f ur,rubik.bur,ru bik.bul)
def D1(): D1_(); rubik.redraw(ru bik.bdl,rubik.b dr,rubik.fdr,ru bik.fdl)
def D2(): D2_(); rubik.redraw(ru bik.fdl,rubik.f dr,rubik.bdr,ru bik.bdl)
def L1(): L1_(); rubik.redraw(ru bik.ful,rubik.b ul,rubik.bdl,ru bik.fdl)
def L2(): L2_(); rubik.redraw(ru bik.fdl,rubik.b dl,rubik.bul,ru bik.ful)
def R1(): R1_(); rubik.redraw(ru bik.fur,rubik.b ur,rubik.bdr,ru bik.fdr)
def R2(): R2_(); rubik.redraw(ru bik.fdr,rubik.b dr,rubik.bur,ru bik.fur)
def solve():
rubik.__init__( )
rubik.display()
def scramble():
n = 15
from random import randint
f = [F1_,F2_,B1_,B2_ ,U1_,U2_,D1_,D2 _,L1_,L2_,R1_,R 2_]
for i in range(n): f[randint(0,11)]()
rubik.display()
canvaswidth = 380
canvasheight = 330
def coordinates(x,y ): return (canvaswidth/2+68*x),(canvas height/2-68*y)
def drawcircle(x,y, color):
r = (20,15)[abs(x)==1]
a,b = coordinates(x,y )
canvas.create_o val(a-r,b-r,a+r,b+r,fill= color)
def drawpointer(x1, y1,x2,y2,color) :
a1,b1 = coordinates(x1, y1)
a2,b2 = coordinates(flo at(x1+x2)/2,float(y1+y2)/2)
canvas.create_l ine(a1,b1,a2,b2 ,width=2,fill=c olor,arrow=LAST )
def erase(x,y):
a,b = coordinates(x,y )
p = canvas.find_ove rlapping(a-10,b-10,a+10,b+10)
q = [x for x in p if canvas.type(x) in ('oval','line')]
for x in q: canvas.delete(x )
def drawbackground( ):
A = coordinates(+1, +1)
B = coordinates(+1,-1)
C = coordinates(-1,+1)
D = coordinates(-1,-1)
E = coordinates(+2, +2)
F = coordinates(+2,-2)
G = coordinates(-2,+2)
H = coordinates(-2,-2)
canvas.create_p olygon(fill='', outline='black' ,*(C+A+E+G+C))
canvas.create_p olygon(fill='', outline='black' ,*(C+G+H+D+C))
canvas.create_p olygon(fill='', outline='black' ,*(A+E+F+B+A))
canvas.create_p olygon(fill='', outline='black' ,*(H+F+B+D+H))
from Tkinter import *
root = Tk()
############### ############### ############### ###########
back = Frame(root,bord erwidth=3)
back.pack(side= TOP)
Button(back,tex t='<<<<',comman d=B1).pack(side =LEFT)
Label(back,widt h=10,text='BACK ').pack(side=LE FT)
Button(back,tex t='>>>>',comman d=B2).pack(side =LEFT)
############### ############### ############### ###########
top = Frame(root,bord erwidth=3)
top.pack(side=T OP)
Button(top,text ='<<<<',command =U1).pack(side= LEFT)
Label(top,width =10,text='TOP') .pack(side=LEFT )
Button(top,text ='>>>>',command =U2).pack(side= LEFT)
############### ############### ############### ###########
mid = Frame(root)
mid.pack(side=T OP)
left = Frame(mid,borde rwidth=5)
left.pack(side= LEFT)
Button(left,tex t='^\n^',width= 3,command=L1).p ack(side=TOP)
Label(left,heig ht=6,text='L\nE \nF\nT').pack(s ide=TOP)
Button(left,tex t='v\nv',width= 3,command=L2).p ack(side=TOP)
canvas = Canvas(mid,widt h=canvaswidth,h eight=canvashei ght)
canvas.pack(sid e=LEFT,expand=1 ,fill=BOTH)
right = Frame(mid,borde rwidth=5)
right.pack(side =LEFT)
Button(right,te xt='^\n^',width =3,command=R1). pack(side=TOP)
Label(right,hei ght=6,text='R\n I\nG\nH\nT').pa ck(side=TOP)
Button(right,te xt='v\nv',width =3,command=R2). pack(side=TOP)
############### ############### ############### ###########
bottom = Frame(root,bord erwidth=3)
bottom.pack(sid e=TOP)
Button(bottom,t ext='<<<<',comm and=D1).pack(si de=LEFT)
Label(bottom,wi dth=10,text='BO TTOM').pack(sid e=LEFT)
Button(bottom,t ext='>>>>',comm and=D2).pack(si de=LEFT)
############### ############### ############### ###########
front = Frame(root,bord erwidth=3)
front.pack(side =TOP)
Button(front,te xt='<<<<',comma nd=F1).pack(sid e=LEFT)
Label(front,wid th=10,text='FRO NT').pack(side= LEFT)
Button(front,te xt='>>>>',comma nd=F2).pack(sid e=LEFT)
############### ############### ############### ###########
ctrl = Frame(root,bord erwidth=20)
ctrl.pack(side= TOP)
Button(ctrl,tex t='SOLVE',comma nd=solve).pack( side=LEFT)
Label(ctrl,widt h=3,text='').pa ck(side=LEFT)
Button(ctrl,tex t='SCRAMBLE',co mmand=scramble) .pack(side=LEFT )
############### ############### ############### ###########
root.title('rub ik')
drawbackground( )
rubik.display()
root.mainloop()
Sean McIlroy wrote: i'm using the canned colors ("pink", "orange", etc). should i try changing to explicit color specifications to see if that makes a difference? i'm not sure what the other guy meant by a "soft toy", but i take it the idea is to try and construct a correctness proof for the script, and see what keeps it (the proof) from working. it's a sound idea, of course, but the script is pretty darn straightforward , as you can see (below). anyway, i'll let you know how it turns out.
peace
Hmm... It worked fine for me. I'm using python 2.4.1 on windows XP.
I didn't see anything particularly wrong with the program that might
cause the problem you are referring to. So I'm afraid I can't help much.
Maybe someone with 2.3 can reproduce it?
BTW, Nice puzzle, much harder than it looks.
Cheers,
Ron
hi ron
changing from english words to hexadecimal numerals did the trick for
me, so everything's cool now. thanks for looking at it.
peace 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: srijit |
last post by:
Hello,
Any idea - why the following code crashes on my Win 98 machine with
Python 2.3? Everytime I run this code, I have to reboot my machine.
I also have Win32all-157 installed.
from Tkinter import *
class App:
|
by: syed_saqib_ali |
last post by:
Please take a look at and run the code snippet shown below.
It creates a canvas with vertical & Horizontal scroll-bars.
If you shrink the window to smaller than the area of the canvas, the
scroll-bars work as advertised. That's great.
However, if you click the Left Mouse button, it calls code which
expands the width of the canvas by 100 pixels. The area being viewed
expands correspondingly..... BUT I DON'T WANT IT TO!!
|
by: Frank |
last post by:
Hi,
we are using oracle clients (Release 9.0.1.0.1 - Production)
on an NT4 (Service Pack6) computers. the server is a W2K,
(Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production
With the Partitioning option,JServer Release 9.0.1.1.1 - Production) machine.
now we are going to update several of those client boxes
to a dual processor board. - great thinking but they are
randomly crashing to blues screen. okay it is ms
but the old...
|
by: syed_saqib_ali |
last post by:
Below is a simple code snippet showing a Tkinter Window bearing a
canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine.
When you shrink/resize the window the scrollbars adjust accordingly.
However, what I really want to happen is that the area of the canvas
that the scrollbars show (the Scrollregion) should expand as the window
grows. It doesn't currently do this. although, if the window shrinks
smaller than the...
| |
by: Michael Yanowitz |
last post by:
Hello:
Below I have included a stripped down version of the GUI I am working on.
It contains 2 dialog boxes - one main and one settings. It has the following
problems, probably all related, that I am hoping someone knows what I am
doing wrong:
1) Pressing the Settings.. Button multiple times, brings up many instances
of the Settings Panel. I just want it to bring up one. Is there an easy
way to do that?
|
by: dwelch91 |
last post by:
I'm trying unsuccessfully to do something in Tk that I though would be
easy. After Googling this all day, I think I need some help. I am
admittedly very novice with Tk (I started with it yesterday), so I am
sure I am overlooking something simple.
The basic idea is that my application will consist of a series of modal
dialogs, that are chained together in "wizard" fashion. There will be
some processing in between dialogs, but for the most...
|
by: yvesd |
last post by:
hello i want to intercept tkinter python system events like
wm_delete_window
and if possible for any window, but the newest code I've produced give
me
an error :
Traceback (most recent call last):
File "C:\Documents and Settings\yvesd\Bureau\protowin.py", line 36,
in ?
b1 = Tkinter.Button (win1)
|
by: karthikbalaguru |
last post by:
Hi,
One of my python program needs tkinter to be installed to run
successfully.
I am using Redhat 9.0 and hence tried installing by copying the
tkinter-2.2.2-36.i386.rpm
alone from the CD 3 to my pc. But, it is not getting installed and is
failing by throwing
the below errors. Should i need to configure / install any specific
files for resolving this issue ?
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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...
| | |