TMS 119
New Member
The spreadsheet is due today and i needed help with the last two parts of the spreadsheet, so I went to my teacher. My spreedsheet was working BETTER before he made me change it. Now it prints a widget address in one of the cells for no apparant reason (I can't locate why the event is doing that), and it doesn't evaluate.
He wants me to use 2 dictionaries:
One that holds the cell number and expression, and
Two that holds the result of evaluating the expression.
He wrote out pseudocode for the evaluating process, and it isn't working at all.
When mouse clicking in the cell of the spreadsheet, the equation should show, if the equation was initially evaluated.
These are the two things I would like help with, because I will never get the third part (this thing is due tonight), where one references a cell with an equation or two cells and they are evaluated.
I'm mostly upset because the way I had it previously works better than what it is doing now. Here is the code, HELP!!!!! -
from Tkinter import *
-
class spreadsheet(Frame):
-
"""
-
initialize columns and rows, default of 5
-
"""
-
def __init__(self, parent=None, nr=4, nc=4):
-
Frame.__init__(self, parent)
-
self.numrow = nr
-
self.numcol = nc
-
self.entriesDict = {} # an empty dictionary
-
self.makeWidgets(nr, nc)
-
def onEvent(self, event, cellName, cellEntry):
-
""" define events, evaluate and show cell
-
"""
-
if event.num == 1:
-
#should retreive equation from dictionary then print it
-
equation = self.entriesDict[cellName]
-
cellEntry.insert(0, equation)
-
-
def returnKey(self, event, cellName, cellEntry):
-
"""
-
define returnKey event
-
"""
-
"""
-
self.entriesDict[cellName] = cellEntry.get()
-
try:
-
result = eval(data, self.entriesDict)
-
cellData.delete(0, 'end') #delete all text in the widget
-
cellData.insert(0, str(result)) #replace with result
-
except:
-
pass #nothing should crash the spreadsheet
-
"""
-
self.entriesDict[cellName] = cellEntry.get()
-
dictNew={}
-
for keys in self.entriesDict:
-
expr = self.entriesDict[keys]
-
#evaluate expr using dictNew
-
result=eval(expr, self.entriesDict)
-
#put result in dictNew under key
-
cellData.insert(0, str(result))
-
def makeWidgets(self, numrow, numcol):
-
"""
-
define labels for rows and columns, use entry widget, assign events, create dictionary of
-
cell:widget pair
-
"""
-
dict = {}
-
w = 20
-
h = 1
-
rowLabel = ["", 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
-
for row in range(numrow):
-
for col in range(numcol):
-
if col == 0:
-
# label rows
-
labels = Label(root, width = 3, text = rowLabel[row])
-
labels.grid(row=row, column=col, padx = 2, pady = 2)
-
elif row == 0:
-
# label columns
-
labels = Label(root, width=3, text = str(col-1))
-
labels.grid(row=row, column=col, padx = 2, pady =2)
-
else:
-
# use entry widget
-
cellEntry = Entry(root, width=w)
-
cellEntry.grid(row=row, column=col)
-
cellName = "%s%s" %(rowLabel[row], col-1)
-
self.entriesDict[cellName] = cellEntry
-
# bind to left mouse click
-
cellEntry.bind('<Button-1>', lambda e, cellName=cellName: self.onEvent(e, cellName, cellEntry))
-
# bind the object to a right mouse click
-
cellEntry.bind('<Tab>', lambda e, cellName=cellName: self.returnKey(e, cellName, cellEntry))
-
# bind the object to a return/enter press
-
cellEntry.bind('<Return>', lambda e, cellName=cellName: self.returnKey(e, cellName, cellEntry))
-
-
if __name__ == '__main__':
-
import sys
-
root = Tk()
-
root.title('S P R E A D S H E E T')
-
if len(sys.argv) != 3:
-
spreadsheet(root).grid()
-
else:
-
rows, cols = eval(sys.argv[1]), eval(sys.argv[2])
-
spreadsheet(root, rows, cols).grid()
-
root.mainloop()
-
-
2 1783 bartonc 6,596
Recognized Expert Expert
I hope this gets you going in the right direction: - from Tkinter import *
-
class spreadsheet(Frame):
-
"""
-
initialize columns and rows, default of 5
-
"""
-
def __init__(self, parent=None, nr=4, nc=4):
-
Frame.__init__(self, parent)
-
self.numrow = nr
-
self.numcol = nc
-
self.entryValueDict = {} # an empty dictionary
-
self.entryFormulaDict = {} # an empty dictionary
-
self.makeWidgets(nr, nc)
-
-
def makeWidgets(self, numrow, numcol):
-
"""
-
define labels for rows and columns, use entry widget, assign events, create dictionary of
-
cell:widget pair
-
"""
-
dict = {}
-
w = 20
-
h = 1
-
rowLabel = ["", 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
-
for row in range(numrow):
-
for col in range(numcol):
-
if col == 0:
-
# label rows
-
labels = Label(root, width = 3, text = rowLabel[row])
-
labels.grid(row=row, column=col, padx = 2, pady = 2)
-
elif row == 0:
-
# label columns
-
labels = Label(root, width=3, text = str(col-1))
-
labels.grid(row=row, column=col, padx = 2, pady =2)
-
else:
-
# use entry widget
-
cellEntry = Entry(root, width=w)
-
cellEntry.grid(row=row, column=col)
-
cellName = "%s%s" %(rowLabel[row], col-1)
-
self.entryValueDict[cellName] = cellName # just testing; should be ""
-
self.entryFormulaDict[cellName] = ""
-
# bind to left mouse click
-
cellEntry.bind('<Button-1>', lambda e, cellName=cellName: self.onEvent(e, cellName, cellEntry))
-
# bind the object to a right mouse click
-
cellEntry.bind('<Tab>', lambda e, cellName=cellName: self.returnKey(e, cellName, cellEntry))
-
# bind the object to a return/enter press
-
cellEntry.bind('<Return>', lambda e, cellName=cellName: self.returnKey(e, cellName, cellEntry))
-
-
-
def onEvent(self, event, cellName, cellEntry):
-
""" define events, evaluate and show cell
-
"""
-
# you can get red if cellEntry and get the Entry from the event.
-
thisEntry = event.widget
-
if event.num == 1:
-
#should retreive equation from dictionary then print it
-
equation = self.entryValueDict[cellName]
-
# need to clear the Entry here
-
thisEntry.insert(0, equation)
-
-
def returnKey(self, event, cellName, cellEntry):
-
"""
-
define returnKey event
-
"""
-
"""
-
self.entriesDict[cellName] = cellEntry.get()
-
try:
-
result = eval(data, self.entriesDict)
-
cellData.delete(0, 'end') #delete all text in the widget
-
cellData.insert(0, str(result)) #replace with result
-
except:
-
pass #nothing should crash the spreadsheet
-
"""
-
self.entriesDict[cellName] = cellEntry.get()
-
dictNew={}
-
for keys in self.entriesDict:
-
expr = self.entriesDict[keys]
-
#evaluate expr using dictNew
-
result=eval(expr, self.entriesDict)
-
#put result in dictNew under key
-
cellData.insert(0, str(result))
-
-
-
-
-
if __name__ == '__main__':
-
import sys
-
root = Tk()
-
root.title('S P R E A D S H E E T')
-
if len(sys.argv) != 3:
-
spreadsheet(root).grid()
-
else:
-
rows, cols = eval(sys.argv[1]), eval(sys.argv[2])
-
spreadsheet(root, rows, cols).grid()
-
root.mainloop()
-
bartonc 6,596
Recognized Expert Expert
I hope this gets you going in the right direction: - from Tkinter import *
-
class spreadsheet(Frame):
-
"""
-
initialize columns and rows, default of 5
-
"""
-
def __init__(self, parent=None, nr=4, nc=4):
-
Frame.__init__(self, parent)
-
self.numrow = nr
-
self.numcol = nc
-
self.entryValueDict = {} # an empty dictionary
-
self.entryFormulaDict = {} # an empty dictionary
-
self.makeWidgets(nr, nc)
-
-
def makeWidgets(self, numrow, numcol):
-
"""
-
define labels for rows and columns, use entry widget, assign events, create dictionary of
-
cell:widget pair
-
"""
-
dict = {}
-
w = 20
-
h = 1
-
rowLabel = ["", 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
-
for row in range(numrow):
-
for col in range(numcol):
-
if col == 0:
-
# label rows
-
labels = Label(root, width = 3, text = rowLabel[row])
-
labels.grid(row=row, column=col, padx = 2, pady = 2)
-
elif row == 0:
-
# label columns
-
labels = Label(root, width=3, text = str(col-1))
-
labels.grid(row=row, column=col, padx = 2, pady =2)
-
else:
-
# use entry widget
-
cellEntry = Entry(root, width=w)
-
cellEntry.grid(row=row, column=col)
-
cellName = "%s%s" %(rowLabel[row], col-1)
-
self.entryValueDict[cellName] = cellName # just testing; should be ""
-
self.entryFormulaDict[cellName] = ""
-
# bind to left mouse click
-
cellEntry.bind('<Button-1>', lambda e, cellName=cellName: self.onEvent(e, cellName, cellEntry))
-
# bind the object to a right mouse click
-
cellEntry.bind('<Tab>', lambda e, cellName=cellName: self.returnKey(e, cellName, cellEntry))
-
# bind the object to a return/enter press
-
cellEntry.bind('<Return>', lambda e, cellName=cellName: self.returnKey(e, cellName, cellEntry))
-
-
-
def onEvent(self, event, cellName, cellEntry):
-
""" define events, evaluate and show cell
-
"""
-
# you can get red if cellEntry and get the Entry from the event.
-
thisEntry = event.widget
-
if event.num == 1:
-
#should retreive equation from dictionary then print it
-
equation = self.entryValueDict[cellName]
-
# need to clear the Entry here
-
thisEntry.insert(0, equation)
-
-
def returnKey(self, event, cellName, cellEntry):
-
"""
-
define returnKey event
-
"""
-
"""
-
self.entriesDict[cellName] = cellEntry.get()
-
try:
-
result = eval(data, self.entriesDict)
-
cellData.delete(0, 'end') #delete all text in the widget
-
cellData.insert(0, str(result)) #replace with result
-
except:
-
pass #nothing should crash the spreadsheet
-
"""
-
self.entriesDict[cellName] = cellEntry.get()
-
dictNew={}
-
for keys in self.entriesDict:
-
expr = self.entriesDict[keys]
-
#evaluate expr using dictNew
-
result=eval(expr, self.entriesDict)
-
#put result in dictNew under key
-
cellData.insert(0, str(result))
-
-
-
-
-
if __name__ == '__main__':
-
import sys
-
root = Tk()
-
root.title('S P R E A D S H E E T')
-
if len(sys.argv) != 3:
-
spreadsheet(root).grid()
-
else:
-
rows, cols = eval(sys.argv[1]), eval(sys.argv[2])
-
spreadsheet(root, rows, cols).grid()
-
root.mainloop()
-
This might fix the other problem of always insterting into the last cell: - # bind to left mouse click
-
cellEntry.bind('<Button-1>', lambda e, cellName=cellName, cellEntry=cellEntry: self.onEvent(e, cellName, cellEntry))
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Rob T |
last post by:
I have a routine that imports a list of part numbers into a dataview:
strExcel = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
boxFile.Text & ";Extended Properties=""Excel 8.0;HDR=NO"""
cnnExcel = New OleDbConnection(strExcel)
da = New OleDbDataAdapter("Select * from ", cnnExcel)
da.Fill(ds, "Excel")
dv = New...
|
by: Paulers |
last post by:
Is there an event that gets triggered when the spreadsheet control
loads? I am trying to modify my column headers so when the spreadsheet
loads, the column headers are displayed.
thanks
|
by: Joseph Geretz |
last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm
adding matching pairs of Toolbar buttons and Menu items. All of the buttons
and menu items are wired up to send events to the same method (aka
delegate?). I use the Tag property within this method to determine what user
action is taking place. Very simple:
When...
|
by: Ian |
last post by:
Hi everyone,
I have found some bizarre (to me...!) behaviour of the Form_Activate
function. I have a form which has a button control used to close the
form and a subform with a datasheet view showing a list of jobs from
the database. When the main form loses focus and the user clicks the
'Close' button, I kept receiving error 2585 (This...
|
by: toffee |
last post by:
Hi all,
I created a little button which when clicked will run a query on mysql db
and output the results as an excel spreadsheet.
I do this by setting the header as application excel. All works well except
for a very strange problem. Let's say a column should say 16500.22. When I
run it here from the uk, the cell will show 16500.22
When...
| |
by: See_Red_Run |
last post by:
I am working with a database that isn't automated ie no switchboard or
similar device was made. I've pretty much gotten everything added to
the
switchboard except for two related key parts.
Right now, what I do is open a table called tbl-Temp, then use the
import
feature to point to an Excel spreadsheet. I select the area to be
imported...
|
by: TMS |
last post by:
Only a few weeks of school left. This assignment and then a project to go (GASP).
I'm writing a spreadsheet. I am required to have each 'cell' do 2 things: Evaluate if it is an equation, or if its a string just print it. Also, it is supposed to print the cell number on a different event reuqest.
Right now, I'm trying to get it to...
|
by: oliver james |
last post by:
I'm trying to automate an Excel spreadsheet from Access. I've
established a link and loaded data from a recordset onto a worksheet
in Excel. I now want to perform some manipulation on the data. I
previously set up a command button in the spreadsheet to run the VBA
to do this manipulation; this VBA is stored in the button's Click
event. Now...
|
by: jit007 |
last post by:
HI!!
I'm using OWC11 spreadsheet control in a VBA application. I want to do two things as described below:--
1. I want to track the KEYDOWN event when user have selected any cell in the column "D". This is because, I want to track the change in the value of the cells under the column "D".
2. I want to prevent the User from...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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
| |