Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

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)
        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)            
        ent.pack(side=RIGHT, expand=YES, fill=X)
    return entries

def callback(e):
    r = Tk()
    r.clipboard_append('<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"><Document><name>KmlFile</name><Schema 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>')

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)

Any help would be appriciated.

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

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[i].get().

Bob Rashkin

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

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.


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.

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

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close