Danke auch für deinen Tipp. Habe mein Skript wieder korrigiert:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Tkinter for Python 3.xx
import tkinter as tk
APP_TITLE = "Button placing with pack layouter"
APP_XPOS = 100
APP_YPOS = 100
APP_WIDTH = 600
APP_HEIGHT = 200
SIDES = ['top', 'right', 'bottom', 'left']
ANCHORS = ['center', 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw']
FONT = ('Helevetica', 14, 'bold')
class Application(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.title(APP_TITLE)
self.build()
def build(self):
self.protocol("WM_DELETE_WINDOW", self.close_app)
self.geometry("+{}+{}".format(APP_XPOS, APP_YPOS))
self.geometry("{}x{}".format(APP_WIDTH, APP_HEIGHT))
self.option_add("*Button.highlightThickness", 0)
frame = tk.Frame(self, bg='#FFFF00')
frame.pack(fill='both', expand=True)
self.pos_var = tk.StringVar()
self.button = tk.Button(frame, textvariable=self.pos_var, width=18,
height=2, font=FONT)
self.button.pack(padx=10, pady=10)
self.place_the_button()
def place_the_button(self, pos_index=0, pos_mode='side'):
if pos_mode == 'side':
side = SIDES[pos_index]
self.pack_with_side(side)
pos_index += 1
if pos_index >= len(SIDES):
pos_index = 0
pos_mode = 'anchor'
elif pos_mode == 'anchor':
anchor = ANCHORS[pos_index]
self.pack_with_anchor(anchor)
pos_index += 1
if pos_index >= len(ANCHORS):
pos_index = 0
pos_mode = 'side'
self.after(2000,self.place_the_button, pos_index, pos_mode)
def pack_with_side(self, side):
# Wichtige voreingestellte Optionen für die Anwendung von 'side' sind:
# 'anchor' = 'center'
# 'expand' = False
print('Side:', self.button.pack_info())
self.button.config(bg='#90EE90')
self.pos_var.set("Position with side:\n'{}'".format(side))
self.button.pack_configure(side=side, anchor='center', expand=False)
def pack_with_anchor(self, anchor):
# Wichtige voreingestellte Optionen für die Anwendung von 'anchor' sind:
# 'expand' = True
print('Anchor:', self.button.pack_info())
self.button.config(bg='#1AB7EA')
self.pos_var.set("Position with anchor:\n'{}'".format(anchor))
self.button.pack_configure(anchor=anchor, expand=True)
def close_app(self):
# Here do something before apps shutdown
print("Good Bye!")
self.destroy()
def main():
app = Application()
app.mainloop()
if __name__ == '__main__':
main()
Gruss wuf