Code: Alles auswählen
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 11 16:11:26 2017
@author: Karl Kraft
"""
import sys
from Tkinter import *
def build_gui():
"Build the GUI, Return root, entry, and personalized greeting label"
rootWindow = Tk()
rootWindow.wm_geometry("500x200")
label1 = Label(rootWindow)
label1['text'] = "Hello, Tkinter World!"
label1.pack()
label2 = Label(rootWindow)
label2['text'] = "What's your name?"
label2.pack()
nameEntry = Entry(rootWindow)
nameEntry.bind('<Key-Return>', entry_callback)
nameEntry.pack(fill=X)
okButton = Button(rootWindow)
okButton['text'] = 'OK'
okButton['command'] = entry_callback
okButton.pack(fill=X)
exitButton = Button(rootWindow)
exitButton['text'] = 'Exit'
exitButton['command'] = exit_callback
exitButton.pack(fill=X)
outLabel = Label(rootWindow)
outLabel['text'] = ''
outLabel.pack()
return rootWindow, nameEntry, outLabel
def entry_callback(event=None):
"Called when the Return key is hit in the entry field or OK is clicked"
name = theEntry.get()
theLabel['text'] = "Nice to meet you, %s" % name
def exit_callback():
"Called when the Exit button is hit"
sys.exit(0)
def main():
global theRoot, theEntry, theLabel
theRoot, theEntry, theLabel = build_gui()
theRoot.mainloop()
if __name__ == '__main__':
main()
Als Python-Neuling arbeite ich mit dem Buch:
Farid Hajji: Das Python Praxisbuch – Der große Profi-Leitfaden für Programmierer.
Es geht schon beschissen los! Ich habe den Code von Seite 78 minutiös eingetippt (hängt diesem Forumsbeitrag an) und erhalte 13 gelbe Warndreiecke. (als Entwicklungsumgebung nutze ich Anaconda Navigator 1.4.3 bzw. spyder 3.1.2) Lasse ich das Skript laufen, stürzt es ab.
Was läuft hier schief?
Grüße,
Strawk