Sie sind hier: Python
Zurück zu: Sprachen
Allgemein:
Vorlesungen
Labore
Sinnvolle Programme
Lineare Regression
GUI-Entwurfsarbeit
Single-Format
Design Pattern-Termine
Observer1
Bsp2
Json-Array
Json-Dialogelemente
Webtechnologien
Erzeugen:
inputui = tkinter.Entry(self)
Setter/Getter:
self.var_name = tkinter.StringVar()
self.var_name.set("Ihr Name...")
self.inputui["textvariable"] = self.var_name
Alternative "Variablen:
self.var_inputfield = tkinter.IntVar()
self.var_inputfield = tkinter.DoubleVar()
Trotz "Variable" benötigt man ein try/except
try:
__zahl1 = self.var_inputfield.get()
except:
__messagebox.showerror( "Fehler", "Fehlerhafte Zahl")
__returnLayout-Manager:
self.inputui.pack oder self.textui.grid()
ActiveBackground:
self.inputui.config(activebackground= "yellow")
funktioniert nicht bei Tests
ActiveForeground:
self.input.config(activeforeground = "green")
funktioniert nicht bei Tests
Background:
self.inputui.config(background = "green")
self.inputui.config(background = "#FF0000")
self.inputui.config(bg = "#FF0000")
Foreground:
self.inputui.config(foreground="red")
self.inputui.config(fg="red")
Borderwidth:
self.inputui.config(borderwidth="2") #pixel
Borderwidth:
self.inputui.config(bd="2") # pixel
Height:
self.inputui.config(height="2") # Textzeilen
Justify:
self.inputui.config(justify("left")
self.inputui.config(justify("right")
self.inputui.config(justify("justify")
overrelief:
self.inputui.config(overrelief="raised") Mouse Hover
sunken
flat
ridge
solid
groove
relief:
self.inputui.config(relief="raised")
sunken
flat
ridge
solid
groove
state:
self.inputui.config(state="normal")
active
enabled
disabled
# coding=utf8
import tkinter
from tkinter import messagebox
class MyApp(tkinter.Frame):
def __init__(self, master=None):
tkinter.Frame.__init__(self, master)
self.pack(expand=True, fill="both") # dialog zoomt
self.setGUI()
def setGUI(self):
# pack ist wie das DockPanel in WPF
# erst muessen die "normalen" UI-Elemente eintgetragen werden
# am Schluss werden die UI-Elemente eingetragen, die fill="both" haben
inputframe = tkinter.Frame(self) # „JPanel“ fuer die Eingabe
inputframe.config(background = "red") #"#FF0000"
inputframe.pack(fill="x", side="top" ) # ohne expand, da fill=“x“
self.label1 = tkinter.Label(inputframe, fg="blue", bg="#FFFF00")
self.label1["text"] = "Eingabe"
self.label1.pack(side="left")
self.inputui = tkinter.Entry(inputframe)
self.inputui.pack(expand=True,fill="x",padx="5",pady="5")
self.var_name = tkinter.StringVar()
self.var_name.set("Ihr Name...")
self.inputui["textvariable"] = self.var_name
buttonframe = tkinter.Frame(self) # „JPanel“ fuer die Eingabe
buttonframe.config(background = "blue") #"#FF0000"
# ohne expand, da fill=“x“
buttonframe.pack(fill="x", side="bottom" )
self.bnEsc = tkinter.Button(buttonframe)
self.bnEsc["text"] = "Beenden"
self.bnEsc["command"] = self.quit
self.bnEsc.pack(padx="5", side="right")
self.bnAction = tkinter.Button(buttonframe)
self.bnAction["text"] = "Action"
self.bnAction["command"] = self.onAction
self.bnAction.pack(side="right")
self.bnAction.config(foreground= "green")
def onAction(self):
str = self.var_name.get()
messagebox.showinfo( "Hello Python", str)
self.editor.insert("end",str+"\r\n")
root = tkinter.Tk()
root.title("Entry")
root.geometry("200x100")
app = MyApp(root)
app.mainloop()
Gehe zu: Checkbutton Frame