473,772 Members | 3,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

change color

I tested the following code and wanted to make oval 2 become red after
I hit the enter key but though the code did not report error, it did
not change.
from Tkinter import *
root=Tk()
canvas=Canvas(r oot,width=100,h eight=100)
canvas.pack()
canvas.create_o val(10,10,20,20 ,tags='oval1',f ill='blue')
canvas.create_o val(50,50,80,80 ,tags='oval2',f ill='yellow')
def turnRed(self, event):
event.widget["activeforegrou nd"] = "red"
self.button.bin d("<Enter>", self.turnRed)
canvas.tag_bind ('oval2',func=t urnRed)
root.mainloop()
Dec 5 '05 #1
1 3012
Ben Bush wrote:
I tested the following code and wanted to make oval 2 become red after
I hit the enter key but though the code did not report error, it did
not change.
from Tkinter import *
root=Tk()
canvas=Canvas(r oot,width=100,h eight=100)
canvas.pack()
canvas.create_o val(10,10,20,20 ,tags='oval1',f ill='blue')
canvas.create_o val(50,50,80,80 ,tags='oval2',f ill='yellow')
def turnRed(self, event):
event.widget["activeforegrou nd"] = "red"
self.button.bin d("<Enter>", self.turnRed)
canvas.tag_bind ('oval2',func=t urnRed)
root.mainloop()


The <Enter> event is triggered when you enter a shape with the mouse
pointer, not when you press the key.
It seems you cannot associate keypress events with shapes, only with the
whole canvas.

Here is some code for you to play with.

import Tkinter

def turnRed(event):
canvas.itemconf igure("oval2", fill="red")

def turnYellow(even t):
canvas.itemconf igure("oval2", fill="yellow")

def keypress(event) :
print "you pressed return or enter"
if "oval2" in canvas.gettags( "current"):
canvas.itemconf igure("current" , fill="green")

root = Tkinter.Tk()

canvas = Tkinter.Canvas( root, width=100, height=100)
canvas.pack()
canvas.create_o val(10, 10, 20, 20, tags="oval1", fill="blue")
canvas.create_o val(50, 50, 80, 80, tags="oval2", fill="yellow")

canvas.tag_bind ("oval2", "<Enter>", turnRed)
canvas.tag_bind ("oval2", "<Leave>", turnYellow)

canvas.bind("<K ey-Return>", keypress)
canvas.bind("<K ey-KP_Enter>", keypress)

canvas.focus_se t()
root.mainloop()

Try pressing Return with the mouse pointer over oval2 and elsewhere on the
canvas.

Peter

Dec 5 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
15210
by: kchengso | last post by:
One of my printers in my printer.devicename call returns in lower case. Is it possible for me to change it to upper case? I am also wondering how, in the first place, this particular printer devicename is coded in lower case? Is there a way to change it back using VB6? Thanks
2
23817
by: Sami | last post by:
I keep getting the famous 'Too Many Connection' Error, and don't know how to change my variables, so they persist even if i have to restart mysql service. Platform: Windows 2003 Server My Program is a WebApplication that is written in VB.Net Using ODBC and OLEDB to connect <- (don't blame me, i just took this over) From what i have read so far, the problem is that i need to change
4
3890
by: J.C. Flores | last post by:
Hello all, First of all, I must state that I'm new to SQL Server, but have been a long-time software guy for quite some time. Please excuse the potential simplicity of the solution to my problem. I create a blank database (TestDB) under my server machine (SQL Server 2000 Standard)... I then create a new table (Run_Number) with only one record in it.
8
9200
by: Patrick Kowalzick | last post by:
Dear NG, I would like to change the allocator of e.g. all std::strings, without changing my code. Is there a portable solution to achieve this? The only nice solution I can think of, would be a namespace and another typedef to basic_string: namespace my_string {
3
8985
by: roger beniot | last post by:
I would like to figure out how to detect an IP address change for an XP/Win2K3 machine that is leasing an IP via DHCP (and do it in C#)... Is there any event that indicates an IP address change?... I really don't want to poll for a change. I would like to get an event indicating the IP address has changed and propogate that change to other levels of my app. If anyone has a solution that isn't in C# I am interested in that as
1
16870
by: Anthony Boudouvas | last post by:
Hi to all, i have a treeview that i put some nodes in it with their repsective images. If i try to change the image and set it to some other ImageList index, nothing happens. The code i use is: private void ChangeServantStatus(string servant, ServantStatus status) {
10
9889
by: Fabrizio | last post by:
(Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all, I try to change the password to a user that as to change the password at first logon: try {
5
2936
by: who be dat? | last post by:
Hello all. I'm writing an application that is writing trace information that can be viewed in trace.axd. I would like to rename this and use a different name specific to my application. I know the name of this is set in machine.config. I was hoping it would be possible to change this in web.config. I got it to work, kind of. Good news is I can change the name in my web.config file. Bad news is that trace.axd still works meaning I can...
4
4455
by: active | last post by:
It appears to me that if I change the Control's client size the controls size does not change to agree with the new size. Does it work like the VB6 ScaleWidth and ScaleHeight? That is after I change the Clientsize does the display stay the same but the number of units required to reference a given point changes? Anyway, it appears to me that If I want to change to size of the control so that the client size is some value, I need to...
3
5016
by: Tom | last post by:
I am writing a Visual basic .Net database application. There are many forms that first let you select and look at a DB record and then when you click a "modify" button you are allowed to change data in the text boxes. Then an "update" button saves the data back to the database. What is the best way to change several properties on most of the textbox controls on the form when the "modify" button is clicked? (e.g. make them editible (and...
0
9620
marktang
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...
0
9454
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,...
0
10104
jinu1996
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...
0
8934
agi2029
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...
1
7460
isladogs
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...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.