http://bytes.com/topic/python/answer...er#post3716687
I'm a beginner in python trying to use the nice code you posted. How can I add a simple menu to the app? The mainloop is in the Entrygrid, and I was not able to put it somewhere else without affecting the functionality of the program.
1 3326 bvdet 2,851
Recognized Expert Moderator Specialist
I have added a simple menu. - import Tkinter
-
import tkMessageBox
-
from time import sleep
-
-
textFont1 = ("Arial", 10, "bold italic")
-
textFont2 = ("Arial", 16, "bold")
-
textFont3 = ("Arial", 8, "bold")
-
-
class LabelWidget(Tkinter.Entry):
-
def __init__(self, master, x, y, text):
-
self.text = Tkinter.StringVar()
-
self.text.set(text)
-
Tkinter.Entry.__init__(self, master=master)
-
self.config(relief="ridge", font=textFont1,
-
bg="#ffffff000", fg="#000000fff",
-
readonlybackground="#ffffff000",
-
justify='center',width=8,
-
textvariable=self.text,
-
state="readonly")
-
self.grid(column=x, row=y)
-
-
class EntryWidget(Tkinter.Entry):
-
def __init__(self, master, x, y):
-
Tkinter.Entry.__init__(self, master=master)
-
self.value = Tkinter.StringVar()
-
self.config(textvariable=self.value, width=8,
-
relief="ridge", font=textFont1,
-
bg="#ddddddddd", fg="#000000000",
-
justify='center')
-
self.grid(column=x, row=y)
-
self.value.set("")
-
-
# Temp function to call from menu
-
def temp():
-
tkMessageBox.showerror("Not done", "This is a temporary message")
-
-
class EntryGrid(Tkinter.Tk):
-
''' Dialog box with Entry widgets arranged in columns and rows.'''
-
def __init__(self, colList, rowList, title="Entry Grid"):
-
self.cols = colList[:]
-
self.colList = colList[:]
-
self.colList.insert(0, "")
-
self.rowList = rowList
-
Tkinter.Tk.__init__(self)
-
self.title(title)
-
-
menubar = Tkinter.Menu()
-
self.config(menu=menubar)
-
optionsMenu = Tkinter.Menu(tearoff=0)
-
menubar.add_cascade(label="Options", menu=optionsMenu)
-
optionsMenu.add_command(label='Milk', command=temp)
-
optionsMenu.add_command(label='Bread', command=temp)
-
optionsMenu.add_command(label='Quit', command=self.destroy)
-
-
self.mainFrame = Tkinter.Frame(self)
-
self.mainFrame.config(padx='3.0m', pady='3.0m')
-
self.mainFrame.grid()
-
self.make_header()
-
-
self.gridDict = {}
-
for i in range(1, len(self.colList)):
-
for j in range(len(self.rowList)):
-
w = EntryWidget(self.mainFrame, i, j+1)
-
self.gridDict[(i-1,j)] = w.value
-
def handler(event, col=i-1, row=j):
-
return self.__entryhandler(col, row)
-
w.bind(sequence="<FocusOut>", func=handler)
-
self.mainloop()
-
-
def make_header(self):
-
self.hdrDict = {}
-
for i, label in enumerate(self.colList):
-
def handler(event, col=i, row=0, text=label):
-
return self.__headerhandler(col, row, text)
-
w = LabelWidget(self.mainFrame, i, 0, label)
-
self.hdrDict[(i,0)] = w
-
w.bind(sequence="<KeyRelease>", func=handler)
-
-
for i, label in enumerate(self.rowList):
-
def handler(event, col=0, row=i+1, text=label):
-
return self.__headerhandler(col, row, text)
-
w = LabelWidget(self.mainFrame, 0, i+1, label)
-
self.hdrDict[(0,i+1)] = w
-
w.bind(sequence="<KeyRelease>", func=handler)
-
-
def __entryhandler(self, col, row):
-
s = self.gridDict[(col,row)].get()
-
if s.upper().strip() == "EXIT":
-
self.destroy()
-
elif s.upper().strip() == "DEMO":
-
self.demo()
-
elif s.strip():
-
self.gridDict[(col,row)].set(s.lower())
-
-
def demo(self):
-
''' enter a number into each Entry field '''
-
for i in range(len(self.cols)):
-
for j in range(len(self.rowList)):
-
sleep(0.25)
-
self.set(i,j,"")
-
self.update_idletasks()
-
sleep(0.1)
-
self.set(i,j,i+1+j)
-
self.update_idletasks()
-
-
def __headerhandler(self, col, row, text):
-
''' has no effect when Entry state=readonly '''
-
self.hdrDict[(col,row)].text.set(text)
-
-
def get(self, x, y):
-
return self.gridDict[(x,y)].get()
-
-
def set(self, x, y, v):
-
self.gridDict[(x,y)].set(v)
-
return v
-
-
if __name__ == "__main__":
-
cols = ['A', 'B', 'C', 'D']
-
rows = ['1', '2', '3', '4']
-
app = EntryGrid(cols, rows)
-
dd = {}
-
for key in app.gridDict:
-
dd[key] = app.gridDict[key].get()
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Patrick L. Nolan |
last post by:
We have a Tkinter application which has a menubar with cascade
submenus. I would like to start the program with one of the
submenu items state=DISABLED, then change it to state=NORMAL
at a later...
|
by: Torsten Mohr |
last post by:
Hi,
i want to write an application where i need a Table to
display some values.
The table should display a list of objects, so to say,
a column for each attribute of the object.
I'd also...
|
by: Summasummarum |
last post by:
Hi,
As subj says. A simple menu is defined in a table. But how to extract it?
Heres the deal:
Table menu has these 3 columns: menuid parent menudesc
Ok this should be easy right?...
|
by: Gordon |
last post by:
VB.Net 2003 Standard -
Creating ASP.Net Web Application
In design mode, I can drag a html table from the toolbox to the work area
but I can't seem to be able to select individual cells or...
|
by: dkimbrell |
last post by:
Hi there,
I'm very novice to web design. I'm trying to make a pulldown menu, but
the formatting keeps getting screwed up when you roll the mouse over
it.
Please see www.boundarysys.com for...
| |
by: leicklda |
last post by:
Hi there,
I'm very novice to web design. I'm trying to make a pulldown menu, but
the formatting keeps getting screwed up when you roll the mouse over
it.
Please see www.boundarysys.com for...
|
by: Carl |
last post by:
"Chuckk Hubbard" <badmuthahubbard@gmail.comwrites:
Try creating the "main" popup menu before the sub-menus, and when
instantiating the sub-menus, pass the main menu as the "master"
instead of...
|
by: dharmbhav |
last post by:
Hello all,
I am trying to develop a roll-over menu effect on a page. It works fine with all other browsers except IE6. Can some one please help me?
HTML:
<div class="menu-item-wrap">...
|
by: xFUNKYFACE |
last post by:
I got a table named "language" were I store all the text from my website (http://www.ultimespace.net/menu/). So in a page I called "sort.php" I actually transfert all the values from the user...
|
by: Neven Huynh |
last post by:
Hi Everyone,
Here i my LINQ query to get record in Table Menu with condition are parentID == 0(get root menu) and ID != (parentID list) (which is parent ID list is are id of menu record that have...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |
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 ...
|
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...
| |