|
Erzeugen:
self.editor = tkinter.Text(self)
Setter/Getter:
self.editor.delete(0.0, "end") self.editor.insert("end",lines)
Layout-Manager: self.editor.pack(expand=True, fill="both" , padx="5",pady="5"= oder self.textui.grid()
ActiveBackground:
self.editor.config(activebackground= "yellow") funktioniert nicht bei Tests
ActiveForeground: self.editor.config(activeforeground = "green") funktioniert nicht bei Tests
Background: self.editor.config(background = "green") self.editor.config(background = "#FF0000") self.editor.config(bg = "#FF0000")
Foreground:
self.editor.config(foreground="red") self.editor.config(fg="red")
Borderwidth: self.editor.config(borderwidth="2") #pixel
Borderwidth: self.editor.config(bd="2") # pixel
Height: self.editor.config(height="2") # Textzeilen
Justify:
self.editor.config(justify("left") self.editor.config(justify("right") self.editor.config(justify("justify")overrelief:
self.editor.config(overrelief="raised") Mouse Hover sunken flat ridge solid groove
relief:
self.editor.config(relief="raised") sunken flat ridge solid groove
state:
self.editor.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
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")
#self.bnAction.config(borderwidth="5")
self.bnAction.config(activebackground= "yellow")
# nun ein Editor mit fill=both
editorframe = tkinter.Frame(self) # „JPanel“ fuer den Editor
editorframe.config(background = "green") #"#FF0000"
editorframe.pack(expand=True,fill="both", side="top" )
sbx = tkinter.Scrollbar(editorframe, orient="horizontal")
sbx.pack(fill="x", side="bottom")
sby = tkinter.Scrollbar(editorframe)
sby.pack(fill="y", side="right")
self.editor = tkinter.Text(editorframe)
self.editor.config(wrap="none") # wrap="word" word char
self.editor.pack(expand=True, fill="both", padx="5",pady="5")
self.editor["xscrollcommand"] = sbx.set
sbx["command"] = self.editor.xview
self.editor["yscrollcommand"] = sby.set
sby["command"] = self.editor.yview
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("Editor")
root.geometry("450x400")
app = MyApp(root)
app.mainloop()
|
|