I have application which creates data table from loaded data, table cells are created using labels.
I am trying to do following: when the mouse cursor is over the one label it will be highlighted using brighter background color -
def mouse_enter(event):
-
self.label["bg"] = "#FFFFFF"
-
-
def mouse_leave(event):
-
self.label["bg"] = "#888888"
-
-
index = 0
-
while index != 10:
-
self.label = Label(frame_x, bg="#888888", text=str(temp[index][0]))
-
self.label.place(x=10, y=35 + (index * 25), width=100)
-
self.label.bind ("Enter", mouse_enter)
-
self.label.bind ("Leave", mouse_leave)
-
index += 1
-
so in the code all labels now get the same name, and ofcourse now they all are highlighted (sorry, only the last one) when mouse cursor will be over any label... but how to name these labels dynamically? (ofcourse the amount of labels isn't 10 in my application, it's based on the amount of data needed to display)
1 2159
solved the problem... not only the dynamic names was problematic but also application needed to send additional info with the event handler...
I'll paste my solution if someone could find this useful ^^ -
def mouse_enter(self, event, index):
-
d["label_a%s" %index]["bg"] = "#FFFFFF"
-
d["label_b%s" %index]["bg"] = "#FFFFFF"
-
-
def mouse_leave(self, event, index):
-
d["label_a%s" %index]["bg"] = "#888888"
-
d["label_b%s" %index]["bg"] = "#888888"
-
-
d = {} #dictionary
-
-
index = 0
-
while index != 10:
-
-
def handler_enter (event, self=self, index=index):
-
return mouse_enter (self, event, index)
-
def handler_leave (event, self=self, index=index):
-
return mouse_leave (self, event, index)
-
-
d["label_a%s" %index] = Label(frame_x, bg="#888888", text=str(temp[index][0]))
-
d["label_a%s" %index].place(x=10, y=35 + (index * 25), width=100)
-
d["label_a%s" %index].bind ("Enter", handler_enter)
-
d["label_a%s" %index].bind ("Leave", handler_leave)
-
-
d["label_b%s" %index] = Label(frame_x, bg="#888888", text=str(temp[index][1]))
-
d["label_b%s" %index].place(x=110, y=35 + (index * 25), width=100)
-
d["label_b%s" %index].bind ("Enter", handler_enter)
-
d["label_b%s" %index].bind ("Leave", handler_leave)
-
-
index += 1
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Edilmar |
last post by:
Hi,
First of all, I'm new in Python...
I have worked with manu langs and IDEs, like Delphi, VB, JBuilder, Eclipse,
Borland C++, Perl, etc...
Then, today I think IDEs like Delphi have a...
|
by: Andrew Dalke |
last post by:
Is there an author index for the new version of the
Python cookbook? As a contributor I got my comp version
delivered today and my ego wanted some gratification.
I couldn't find my entries.
...
|
by: max(01)* |
last post by:
hello.
the following code:
1 from Tkinter import *
2
3 class MiaApp:
4 def __init__(self, genitore):
5 self.mioGenitore = genitore
6 self.i = IntVar()
|
by: ajikoe |
last post by:
Hi,
I tried to follow the example in swig homepage.
I found error which I don't understand.
I use bcc32, I already include directory where my python.h exist in
bcc32.cfg.
/* File : example.c...
|
by: H J van Rooyen |
last post by:
Hi,
I want to write a small system that is transaction based.
I want to split the GUI front end data entry away from the file handling and
record keeping.
Now it seems almost trivially easy...
|
by: bcwhite |
last post by:
I've been trying to find out what the future of Python is with regard
to Tk. It seems there are several interfaces that make use of new
functionality, including "Tile" and "Ttk".
If I want to...
|
by: Kevin Walzer |
last post by:
From the introduction to PyObjC, the Python-Objective-C bridge on Mac OS X:
"As described in Objective-C for PyObjC users the creation of
Objective-C objects is a two-stage process. To initialize...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
| |