473,394 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Press button to load data

I'm new to Python, and programming in general.
What I'm trying to do here is to load a list of accounts from a file on
my harddrive into a string of Buttons in Tkinter, and when I press one
of the Buttons, which has one of my account name, it will load that
account into a new window. But I don't understand how to code the
proccess that would tell the program what account is selected. Any help
with this would be very appreciated. Thanks in advance.

from Tkinter import *
import shelve
from tkMessageBox import showerror

shelvename = shelve.open('class-shelve2')
cat = (' Name ', ' Account # ', ' Amount Due ', ' Date Due ')

def NameFields(top):
name1 = Label(None, text=cat[0], relief=RIDGE, width=20, fg='blue',
bg='white', font=('bold',15))
name2 = Label(None, text=cat[1], relief=RIDGE, width=15, fg='blue',
bg='white', font=('bold',15))
name3 = Label(None, text=cat[2], relief=RIDGE, width=15, fg='blue',
bg='white', font=('bold',15))
name4 = Label(None, text=cat[3], relief=RIDGE, width=15, fg='blue',
bg='white', font=('bold',15))
name1.grid(row=0, column=0, sticky=NSEW)
name2.grid(row=0, column=1, sticky=NSEW)
name3.grid(row=0, column=2, sticky=NSEW)
name4.grid(row=0, column=3, sticky=NSEW)
top.columnconfigure(0, weight=1)
top.columnconfigure(1, weight=1)
top.columnconfigure(2, weight=1)
top.columnconfigure(3, weight=1)
def DisplayBills(top):
c=0
for bill in shelvename:
bill1 = Button(None, text= shelvename[bill].name,
font=('bold',10), command=fetchRecord)
bill2 = Label(None, text= shelvename[bill].account,
relief=RIDGE, font=('bold',10))
bill3 = Label(None, text= shelvename[bill].paymentDue,
relief=RIDGE, font=('bold',10), fg='red')
bill4 = Label(None, text= shelvename[bill].dateDue,
relief=RIDGE, font=('bold',10))
bill1.grid(row=c, column=0, sticky=NSEW)
bill2.grid(row=c,column=1, sticky=NSEW)
bill3.grid(row=c,column=2, sticky=NSEW)
bill4.grid(row=c,column=3, sticky=NSEW)
c = c + 1

def fetchRecord():

top = Tk()

DisplayBills(top), NameFields(top)

mainloop()

Nov 16 '06 #1
3 2161

Just from a glance my thoughts are to
start with one file and build on it. Make
a class of it so you can loop it to use
it over for each record.
You wrote that the info was in a file on
the hd. If it is in a file on the hd, use the
open()
function, read from the file, only one record
and write the data to a list.

You can incorporate the
button option,

"command = CallSomeFunction",

to call a function that builds a window,
and loads the data into labels or
entry boxes.
If you are going to modify
the data, entry boxes allow you to
modify it and save it back to a
file.

Also, when using the open() function,
close it after you get the data you need.
otherwise you may experience
unexpected problems.

client = open('client', 'r')
client.read() (readline()) (readlines())
client.close()

jim-on-linux

http//:www.inqvista.com

On Wednesday 15 November 2006 23:20,
gi*********@msn.com wrote:
I'm new to Python, and programming in general.
What I'm trying to do here is to load a list of
accounts from a file on my harddrive into a
string of Buttons in Tkinter, and when I press
one of the Buttons, which has one of my account
name, it will load that account into a new
window. But I don't understand how to code the
proccess that would tell the program what
account is selected. Any help with this would
be very appreciated. Thanks in advance.

from Tkinter import *
import shelve
from tkMessageBox import showerror

shelvename = shelve.open('class-shelve2')
cat = (' Name ', ' Account # ', ' Amount Due ',
' Date Due ')

def NameFields(top):
name1 = Label(None, text=cat[0],
relief=RIDGE, width=20, fg='blue', bg='white',
font=('bold',15))
name2 = Label(None, text=cat[1],
relief=RIDGE, width=15, fg='blue', bg='white',
font=('bold',15))
name3 = Label(None, text=cat[2],
relief=RIDGE, width=15, fg='blue', bg='white',
font=('bold',15))
name4 = Label(None, text=cat[3],
relief=RIDGE, width=15, fg='blue', bg='white',
font=('bold',15))
name1.grid(row=0, column=0, sticky=NSEW)
name2.grid(row=0, column=1, sticky=NSEW)
name3.grid(row=0, column=2, sticky=NSEW)
name4.grid(row=0, column=3, sticky=NSEW)
top.columnconfigure(0, weight=1)
top.columnconfigure(1, weight=1)
top.columnconfigure(2, weight=1)
top.columnconfigure(3, weight=1)
def DisplayBills(top):
c=0
for bill in shelvename:
bill1 = Button(None, text=
shelvename[bill].name, font=('bold',10),
command=fetchRecord) bill2 = Label(None, text=
shelvename[bill].account, relief=RIDGE,
font=('bold',10))
bill3 = Label(None, text=
shelvename[bill].paymentDue, relief=RIDGE,
font=('bold',10), fg='red') bill4 = Label(None,
text= shelvename[bill].dateDue, relief=RIDGE,
font=('bold',10))
bill1.grid(row=c, column=0,
sticky=NSEW) bill2.grid(row=c,column=1,
sticky=NSEW) bill3.grid(row=c,column=2,
sticky=NSEW) bill4.grid(row=c,column=3,
sticky=NSEW) c = c + 1

def fetchRecord():

top = Tk()

DisplayBills(top), NameFields(top)

mainloop()
Nov 16 '06 #2

Without being able to run the code my question is
where is the id in the lambda defined?
On Thursday 16 November 2006 22:31, jim wrote:
Thanks for your help, but now I have a another
problem so here is my code again
when I run this it prints <built-in function
id>

from Tkinter import *
import shelve
from tkMessageBox import showerror

shelvename = shelve.open('class-shelve2')
cat = (' Name ', ' Account # ', ' Amount Due ',
' Date Due ')

def NameFields(top):
name1 = Label(None, text=cat[0],
relief=RIDGE, width=20, fg='blue', bg='white',
font=('bold',15))
name2 = Label(None, text=cat[1],
relief=RIDGE, width=15, fg='blue', bg='white',
font=('bold',15))
name3 = Label(None, text=cat[2],
relief=RIDGE, width=15, fg='blue', bg='white',
font=('bold',15))
name4 = Label(None, text=cat[3],
relief=RIDGE, width=15, fg='blue', bg='white',
font=('bold',15))
name1.grid(row=0, column=0, sticky=NSEW)
name2.grid(row=0, column=1, sticky=NSEW)
name3.grid(row=0, column=2, sticky=NSEW)
name4.grid(row=0, column=3, sticky=NSEW)
top.columnconfigure(0, weight=1)
top.columnconfigure(1, weight=1)
top.columnconfigure(2, weight=1)
top.columnconfigure(3, weight=1)
def DisplayBills(top):
c=0
x = []
global bill
for bill in shelvename:
global funcs
bill1 = Button(None, text=
shelvename[bill].name,
font=('bold',10),command=(lambda x = id:
fetchRecord(x)))

bill2 = Label(None, text=
shelvename[bill].account, relief=RIDGE,
font=('bold',10))
bill3 = Label(None, text=
shelvename[bill].paymentDue, relief=RIDGE,
font=('bold',10), fg='red') bill4 = Label(None,
text= shelvename[bill].dateDue, relief=RIDGE,
font=('bold',10))
bill1.grid(row=c, column=0,
sticky=NSEW) bill2.grid(row=c,column=1,
sticky=NSEW) bill3.grid(row=c,column=2,
sticky=NSEW) bill4.grid(row=c,column=3,
sticky=NSEW) c = c + 1
return bill

def fetchRecord(x):
print x

top = Tk()

DisplayBills(top), NameFields(top)

mainloop()

jim-on-linux wrote:
Just from a glance my thoughts are to
start with one file and build on it. Make
a class of it so you can loop it to use
it over for each record.
You wrote that the info was in a file on
the hd. If it is in a file on the hd, use the
open()
function, read from the file, only one record
and write the data to a list.

You can incorporate the
button option,

"command = CallSomeFunction",

to call a function that builds a window,
and loads the data into labels or
entry boxes.
If you are going to modify
the data, entry boxes allow you to
modify it and save it back to a
file.

Also, when using the open() function,
close it after you get the data you need.
otherwise you may experience
unexpected problems.

client = open('client', 'r')
client.read() (readline()) (readlines())
client.close()

jim-on-linux

http//:www.inqvista.com
Nov 17 '06 #3
On Friday 17 November 2006 02:58, you wrote:
On Fri, 17 Nov 2006 00:25:39 -0500,
jim-on-linux <in*****@verizon.net>

declaimed the following in comp.lang.python:
Without being able to run the code my
question is where is the id in the lambda
defined?

Please take into account that I've not
actually used lambdas, so might have some
mistakes in the syntax...
for bill in shelvename:
global funcs
bill1 = Button(None, text=
shelvename[bill].name,
font=('bold',10),command=(lambda x = id:
fetchRecord(x)))

"id" would be something that "identifies" the
button... In this case, maybe you can use
"bill":
Think about relating a Tkinter variable to each
button then the button is related to a unique
variable. ( Tkinter StingVar or IntVar or some
others.) Then you will have to keep the variables
in a list or dictionary for recalling.
jim-on-linux
http://www.inqvista.com


... command=(lambda x = bill: fetchRecord(x))
...

As I understand the lambda syntax, what this
does is create a "function" (which is the
command that gets run when the button is
pushed), and this function will call
fetchRecord passing it the value that "x" had
at the time of definition (hence the x=...)
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support
Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/
Nov 17 '06 #4

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

Similar topics

6
by: guoqi zheng | last post by:
In a regular html form, when user press "enter" key, the form will be submitted. However, in ASP.NET web form, a form will only be submitted (post back) when a special button is clicked. Many...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
3
by: raj | last post by:
hi, i have one textbox and one save button, i have added attribute at page load event btnSave.Attributes.Add("onclick","return ValidateForm();"); in validationform() ,I have written like this...
9
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT...
0
by: neeraj | last post by:
Hi Everybody I have one problem in my asp.net web application. The problem is that I check the date validation in code behind; if user not gives the valid data and press save button then I fire...
3
by: GauravGupta | last post by:
i want to know that is it posible to call button click event before page load event on post back.... please help me....
2
by: GauravGupta | last post by:
i am displaying a table in page load whose data is fetched from database . it also check what data is to be displayed from data base by a session variable. and i have few button which change the...
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
1
by: =?Utf-8?B?QXNhZg==?= | last post by:
Hello, I have a Default.aspx page with several controls in a Master Page. When pressing on a Button control Page_Load event is fired on the Default.aspx page and after that the Page_Load event...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
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,...
0
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...

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.