Skip to content

Instantly share code, notes, and snippets.

@NinaLobe
Last active August 8, 2018 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NinaLobe/98172f10c5245d07a9962b98e6162938 to your computer and use it in GitHub Desktop.
Save NinaLobe/98172f10c5245d07a9962b98e6162938 to your computer and use it in GitHub Desktop.
utf-8 problems - python 2.7 and Tkinter
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<elements>
<element>
<SA008>ččžžšš</SA008>
<DI001>Ime</DI001>
<PE019>ocena SLO</PE019>
<PE020>ocena 2</PE020>
<LS003>uspeh</LS003>
</element>
</elements>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from Tkinter import *
def main():
window = Tk()
name_l = Label(window, text=" Ime: ")
name_l.grid(row=2, column=0)
name = Entry(window)
name.grid(row=2, column=1)
# seznam uspehov na spričevalu
uspeh_list = ["izberi", "odličen"]
selected_uspeh = StringVar()
selected_uspeh.set(uspeh_list[0])
uspeh = Label(window, text=" Uspeh: ")
uspeh.grid(row=5, column=0, sticky=E)
uspeh_menu = OptionMenu(window, selected_uspeh, *uspeh_list)
uspeh_menu.grid(row=5, column=1)
# tu še funkcija za pridobivanje podatkov
def get_data():
name_dijak = name.get()
uspeh_dijak = selected_uspeh.get()
podatki_o_spricevalu = {"name": name_dijak, "uspeh":uspeh_dijak}
print podatki_o_spricevalu
return podatki_o_spricevalu
def make_xml():
podatki = get_data()
print ("Tole so podatki v obliki dictionary:")
print podatki
# odpremo pravo xml datoteko
import xml.etree.ElementTree as ET
with open('primer.xml','r') as tree_file:
tree = ET.parse(tree_file)
root = tree.getroot()
name = root[0][1].text
root[0][1].text = podatki["name"]
uspeh = root[0][4].text
root[0][4].text = podatki["uspeh"]
tree.write('primer_out.xml')
print root[0][1].text
# gumb naredi xml
Label(window, text="Make xml:", ).grid(row=20, column=0, sticky=E)
Button(window, text="XML ", width=14, command=make_xml).grid(
row=20, column=1, sticky=E)
window.mainloop()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment