Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tkinter: Appending entries to text to be copied to clipboard.

Status
Not open for further replies.

Bazal

Programmer
Apr 3, 2011
2
0
0
GB
I am close to finishing a program for my A - Level Computing Project. The last problem that need solving is the appending of Entry Field values into a KML code I have also written. Would anyone know how this is done.

This is the source code for the program.

from Tkinter import *

from tkMessageBox import askokcancel

class Quitter(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.pack()
widget = Button(self, text='Quit', command=self.quit)
widget.pack(expand=YES, fill=BOTH, side=LEFT)
def quit(self):
ans = askokcancel('Verify exit', "Really quit?")
if ans: Frame.quit(self)


fields = 'Name','SAR Reprot No.', 'Rotor Start', 'Rotor Stop', 'Nature', 'Alerted By', 'Captian', 'Co Pilot', 'Helicopter','Latitude','Longitude'

def makeform(root, fields):
entries = []
for field in fields:
row = Frame(root)
lab = Label(row, width=15, text=field)
ent = Entry(row)
row.pack(side=TOP, fill=X)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries.append(ent)
return entries

def callback(e):
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append('<?xml version="1.0" encoding="UTF-8"?><kml xmlns=" xmlns:gx=" xmlns:kml=" xmlns:atom=" name="MissionDetails" id="MissionDetailsId"><SimpleField type="string" name="ReportNumberValue"><displayName>&lt;b&gt;ReportNumber&lt;/b&gt;</displayName></SimpleField><SimpleField type="int" name="Date"><displayName>&lt;b&gt;Date&lt;/b&gt;</displayName></SimpleField><SimpleField type="double" name="RotorStart"><displayName>&lt;b&gt;RotorStart&lt;/b&gt;</displayName></SimpleField><SimpleField type="double" name="RotorStop"><displayName>&lt;b&gt;RotorStop&lt;/b&gt;</displayName></SimpleField><SimpleField type="string" name="Nature"><displayName>&lt;b&gt;Nature&lt;/b&gt;</displayName></SimpleField><SimpleField type="string" name="AlertedBy"><displayName>&lt;b&gt;AlertedBy&lt;/b&gt;</displayName></SimpleField><SimpleField type="string" name="Captain"><displayName>&lt;b&gt;Captain&lt;/b&gt;</displayName></SimpleField><SimpleField type="string" name="CoPilot"><displayName>&lt;b&gt;CoPilot&lt;/b&gt;</displayName></SimpleField><SimpleField type="string" name="Helicopter"><displayName>&lt;b&gt;Helicopter&lt;/b&gt;</displayName></SimpleField></Schema><Placemark><name>{makeform(root, fields):entries = [Name].clipboard_append}</name><ExtendedData><SchemaData schemaUrl="#MissionDetailsId"><SimpleData name="Nature">Diver overdue or missing</SimpleData><SimpleData name="AlertedBy">Portland CG</SimpleData><SimpleData name="Captain">Balls K.</SimpleData><SimpleData name="CoPilot">Stracey G.</SimpleData><SimpleData name="Helicopter">G-CGWB</SimpleData></SchemaData><Data name="sarReportNumber"><value>9210</value></Data><Data name="date"><value>26062010</value></Data><Data name="rotorStart"><value>13.19</value></Data><Data name="rotorStop"><value>13.50</value></Data></ExtendedData><gx:balloonVisibility>1</gx:balloonVisibility><Point><coordinates>-1.957759,50.60696,0</coordinates></Point></Placemark></Document></kml>')
r.destroy()

if __name__ == '__main__':
root = Tk()
ents = makeform(root, fields)
root.bind('<Return>', (lambda event, e=ents: callback(e)))
Button(root, text='Print KML',
command=(lambda e=ents: callback(e))).pack(side=LEFT)
Quitter(root).pack(side=RIGHT)
root.mainloop()


Any help would be appriciated.
 
I'm afraid I can't tell what you're trying to do. If you're asking how to retrieve the text from an entry widget, it looks like you have a list of entries, "entries[]". The text in the ith entry would be: entries.get().


_________________
Bob Rashkin
 
Sorry for not explaining in detail earlier, I had to knock this thread up quickly. The program is a KML generator (A form of XML used for placemarks in Google Earth)for a local Search and Rescue company as a replacement for their outdated manual seachart. The system is intended to allow users to input their own variable values into the code so they display in the marker details window. As it stands the program can copy the KML structure on a button click to the Windows clipboard. However I have been unsuccessful in finding a way to append the values input into the entry fields.

@Bong

Unfortunately I wasn't able to get this method working. I tried it as entries[1].get(), if this isn't correct then let me know.
 
It should be. How many elements does "entries" have (and what are they)?

Also, I don't know if the widget names created in "makeform" exist in the global scope. I always make them in a method of the main class. You might want to look at that. Also, you return the "entries" list as "ents" so the entry widgets will be elements of "ents[]" in the global scope.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top