I wanted to write a small program in Python 3.4 where I have to enter a full name like "Gumbo Froehn"
and the program splits it into name and surname. However, I have trouble reading the entry field.
Here is my code (so far):
from tkinter import *
from tkinter import ttk
class FullScreenApp(object): # Klasse fuer die Vollbild Darstellung
def __init__(self, master, **kwargs):
self.master=master
pad=3
self._geom='200x200+0+0'
master.geometry("{0}x{1}+0+0".format(
master.winfo_screenwidth()-pad, master.winfo_screenheight()-pad))
master.bind('<Escape>',self.toggle_geom)
def toggle_geom(self,event):
geom=self.master.winfo_geometry()
print(geom,self._geom)
self.master.geometry(self._geom)
self._geom=geom
mainWindow = Tk() # Generiert das Hauptfenster aus tkinter
app=FullScreenApp(mainWindow) # Ruft Klasse fuer Vollbild-Darstellung auf
mainWindow.title("Mark's Latex Code Generator") # Definiert den fenster-Titel
fullname = StringVar()
LBLeingabename = Label(mainWindow, text="Write full name:").place(x=20, y=350)
EFvollername = Entry(mainWindow,textvariable=str(fullname), width=50)
EFvollername.place(x=200,y=350)
splitname = fullname.get().split()
LBtestausgabe = Label(mainWindow, text="Testausgabe").place(x=20, y=770)
TFtestausgabe = Text(mainWindow, height=5,width=50)
TFtestausgabe.place(x=20,y=800)
def test():
TFtestausgabe.insert(END, EFvollername.get()+"\n")
TFtestausgabe.insert(END, splitname.get()+"\n")
TFtestausgabe.insert(END, type(fullname))
Btn = ttk.Button(mainWindow, text="OK",command=test).place(x=450,y=800)
mainloop() # Haelt das Programm offen bis es beendet wird
When I run the program, only the line TFtestausgabe.insert(END, EFvollername.get()+"\n")
is working, giving me the full name.
I want to use the StringVar
variable fullname
for the string-split operation. But this doesn't work yet. When I use .set()
to enter a predefined name into the fullname
variable it works.
What am I doing wrong? Do I have some of the code lines in the wrong order?