Created
November 9, 2012 15:48
-
-
Save anonymous/4046428 to your computer and use it in GitHub Desktop.
Tkinter, Nebenfenster ohne Funktion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| def list_names(name): | |
| if name == 'kunden': | |
| main_title = 'Anlage Kunden' # listbox_items | |
| sub_title = 'Auswahl Kundenkreis' # default_labels | |
| # Kundendefintion | |
| listbox_items = {'0' : 'Privatkunde', | |
| '1' : 'Kleinbetrieb, bis 1000 € Jahresumsatz', | |
| '2' : 'Mittelständischer Betrieb, bis 10.000 € Jahresumsatz', | |
| '3' : 'Großbetrieb, bis 25.000 € Jahresumsatz', | |
| '4' : 'Konzern, ab 25.000 € Jahresumsatz', | |
| '5' : 'Komunaler Träger'} | |
| # Kundenspalten | |
| default_labels = ['Kundenkreis', 'Namen', 'Zusatz', 'Straße, Nr.', | |
| 'PLZ', 'Ort', 'USt-Ident-Nr.', 'Ansprechpartner', 'Telefon', | |
| 'Handy', 'Fax', 'Mail','Internetseite'] | |
| if name == 'lieferanten': | |
| main_title = 'Anlage Lieferanten' # listbox_items | |
| sub_title = 'Auswahl Lieferantenkreis' # default_labels | |
| # Lieferanten Angebot | |
| listbox_items = {'00' : 'Allgemeiner Büro- und EDV-Bedarf', | |
| '01' : 'Tinte, Toner, Farbbänder', | |
| '02' : 'Papiere, Etiketten und Folien', | |
| '03' : 'EDV-Zubehör, Speichermedien und Elektro-Zubehör', | |
| '04' : 'Konferenz, Schulung und Planung', | |
| '05' : 'Büromöbel, Stühle und Beleuchtung', | |
| '06' : 'Büromaschinen und Zubehör', | |
| '07' : 'Telekomunikation', | |
| '08' : 'Ordnen, Sortieren und Archivieren', | |
| '09' : 'Heften, Lochen, Kleben und Stempeln', | |
| '10' : 'Verpacken und Versenden', | |
| '11' : 'Schneiden und Zeichnen', | |
| '12' : 'Schreiben und Korrigieren', | |
| '13' : 'Bücher, Blöcke und Haftnotitzen', | |
| '14' : 'Kalender und Zeitplansysteme', | |
| '15' : 'Batterien, Haushaltsbedarf und Koffer', | |
| '16' : 'Hygiene und Reinigung', | |
| '17' : 'Bewirtung und Catering', | |
| '18' : 'Arbeitsschutz, Erste Hilfe und Tresore', | |
| '19' : 'Schulbedarf und Kreatives Gestalten', | |
| '20' : 'Kunst, Geschenkideen, Schreibkultur und Dekobedarf'} | |
| # Kundenspalten | |
| default_labels = ['Lieferantenkreis', 'Namen', 'Zusatz', 'Straße, Nr.', | |
| 'PLZ', 'Ort', 'USt-Ident-Nr.', 'Ansprechpartner', 'Telefon', | |
| 'Handy', 'Fax', 'Mail','Internetseite'] | |
| if name == 'produktdaten': | |
| main_title = 'Produktdaten' # listbox_items | |
| sub_title = 'Auswahl Produktdaten' # default_labels | |
| # Produktdaten | |
| listbox_items = {'04711' : 'Kopierpapier DIN A4 80g Müller-AG 0753945128', | |
| '04799' : 'Toilettenpapier Müller-AG 0753949999', | |
| '047815' : 'Versandtasche C4 80g Müller-AG 0753911111',} # Wird aus Liste übergeben | |
| # Produktspalten | |
| default_labels = ['Lieferant / Artikel', 'Hersteller', | |
| 'Herstellernummer', 'VE', 'Inhalt', 'Benennung', 'Beschreibung', | |
| 'Menge', 'Ek', 'Vk'] | |
| try: | |
| return listbox_items, default_labels, main_title, sub_title | |
| except UnboundLocalError: | |
| print('Sorry, Daten für "%s" sind nicht vorhanden!' % name) | |
| exit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| # For Python3.x | |
| import os | |
| import csv | |
| import codecs | |
| import tkinter as tk | |
| import gui_list_names as app_list | |
| listbox_items, default_labels, main_title, sub_title = app_list.list_names('kunden') | |
| CONFIG = {'width' : 0, | |
| 'font': ('NimbusSansL', 14), | |
| 'font_color': 'black', | |
| 'back_ground' : 'orange', | |
| 'select_mode': 'single'} | |
| class ListGui(object): | |
| def __init__(self, controller, items, items2, main_title, sub_title): | |
| self.root = tk.Tk() | |
| self.main_title = main_title | |
| self.sub_title = sub_title | |
| self.root.title(self.main_title) | |
| self.controller = controller | |
| self.conf = CONFIG | |
| xpos = 0 | |
| ypos = 0 | |
| self.screenx = self.root.winfo_screenwidth() | |
| self.screeny = self.root.winfo_screenheight() | |
| self.root.geometry("%dx%d+%d+%d" % (self.screenx, self.screeny, | |
| xpos, ypos)) | |
| self.frame = tk.Frame(self.root) | |
| self.frame.pack(side='top', fill='both', expand=True) | |
| maxline = (max([len(' '.join(item)) for item in sorted(items)])) | |
| minline = (min([len(' '.join(item)) for item in sorted(items)])) | |
| step = (maxline - minline) | |
| if (maxline - minline) == 0: | |
| step = 4 | |
| for item in sorted(items): | |
| if type(items[item]) == tuple: | |
| self.items = ['{0}\t{1}{2}'.format(' '.join(item), | |
| ((maxline + step - len(' '.join(item))) * ' '), | |
| ' '.join(items[item])) for item in sorted(items)] | |
| if type(items[item]) == str: | |
| self.items = ['{0}\t{1}{2}'.format(' '.join(item), | |
| ((maxline + step - len(' '.join(item))) * ' '), | |
| ''.join(items[item])) for item in sorted(items)] | |
| self.items2 = items2 | |
| box_length = len(self.items) | |
| max_items = (max([(len(' '.join(item)) + | |
| len(' '.join(items[item]))) | |
| for item in sorted(items)])) - 5 | |
| if max_items > 160: | |
| max_items = 160 | |
| self.geoxy = set() | |
| if self.sub_title != '': | |
| self.label_name = tk.Label(self.frame, height=2, | |
| width=self.conf['width'], text=self.sub_title, | |
| bg=self.conf['back_ground'], font=self.conf['font'], | |
| bd=0, highlightthickness=0, fg=self.conf['font_color']) | |
| self.label_name.pack(fill='both', expand=False) | |
| self.geoxy.add(self.label_name.winfo_reqheight()) | |
| self.listbox = tk.Listbox(self.frame, width=max_items, | |
| font=self.conf['font'], fg=self.conf['font_color'], | |
| selectmode=self.conf['select_mode'], bd=0, | |
| highlightthickness=0) | |
| self.listbox.pack(pady=30, expand=True) | |
| self.listbox.insert(0, *self.items) | |
| self.listbox.bind('<<ListboxSelect>>', self.check) | |
| self.geoxy.add(self.listbox.winfo_reqheight()) | |
| self.root.config() | |
| self.label_names = self.items2 | |
| self.scr_frame = self.set_scrolled_entries(self.root) | |
| self.scr_frame.pack(expand=True) | |
| self.button_frame = tk.Label(self.root, | |
| bg=self.conf['back_ground']) | |
| self.button_frame.pack(fill='x', ipady=5) | |
| tk.Button(self.button_frame, text="Abbrechen", | |
| font=self.conf['font'], fg=self.conf['font_color'], | |
| highlightthickness=0, command=self.root.destroy,).pack( | |
| side='right', padx=4) | |
| tk.Button(self.button_frame, text="Übernehmen", | |
| font=self.conf['font'], fg=self.conf['font_color'], | |
| highlightthickness=0, | |
| command=self.controller.collect_entries).pack( | |
| side='right', padx=4) | |
| self.geoxy.add(self.button_frame.winfo_reqheight()) | |
| def set_scrolled_entries(self, parent): | |
| self.entry_vars = [tk.StringVar() for _ in self.label_names] | |
| self.entries = list() | |
| scroll_frame = tk.Frame(parent, bg='red') | |
| canvas = tk.Canvas(scroll_frame, highlightthickness=0) | |
| canvas.grid(row=0, column=0, sticky=tk.NSEW) | |
| yscroll = tk.Scrollbar(scroll_frame, orient=tk.VERTICAL, | |
| command=canvas.yview) | |
| yscroll.grid(row=0, column=1, sticky=tk.NS) | |
| canvas.config(yscrollcommand=yscroll.set) | |
| scroll_frame.grid_rowconfigure(0, weight=1) | |
| self.canvas = canvas | |
| self.bind_scroll(yscroll, self.y_scroll) | |
| entry_frame = tk.Frame(canvas) | |
| font = self.conf['font'] | |
| for i, (var, name) in enumerate(zip(self.entry_vars, | |
| self.label_names)): | |
| label = tk.Label(entry_frame, text=name, font=font) | |
| label.grid(row=i, column=0, padx=10, sticky=tk.E) | |
| bg = ('grey', 'grey')[i & 1] | |
| entry = tk.Entry(entry_frame, textvariable=var, width=100, | |
| font=font, bg=bg) | |
| entry.grid(row=i, column=1, pady=2, sticky=tk.W) | |
| self.entries.append(entry) | |
| canvas.create_window(0, 0, window=entry_frame, anchor=tk.NW) | |
| canvas.update_idletasks() | |
| x, y, w, h = entry_frame.bbox(tk.ALL) | |
| y_value = h | |
| if (h * 1.5) > self.screeny: | |
| y_value = (self.screeny - (round(sum(self.geoxy) * 2))) | |
| canvas.config(scrollregion=(x, y, w, h), width=w, height=y_value) | |
| return scroll_frame | |
| def check(self, event): | |
| indices = list(map(int, self.listbox.curselection())) | |
| self.controller.process(self.items[indices[0]]) | |
| def run(self): | |
| self.root.mainloop() | |
| def bind_scroll(self, widget, mode): | |
| #~~ Windows | |
| widget.bind("<MouseWheel>", mode) | |
| #~~ Linux | |
| widget.bind("<Button-4>", mode) | |
| widget.bind("<Button-5>", mode) | |
| def y_scroll(self, event): | |
| if event.num == 5 or event.delta < 0: | |
| self.canvas.yview_scroll(1, "unit") | |
| elif event.num == 4 or event.delta > 0: | |
| self.canvas.yview_scroll(-1, "unit") | |
| class Controller(object): | |
| def __init__(self, name): | |
| listbox_items, default_labels, main_title, sub_title = app_list.list_names(name) | |
| self.model = Model(listbox_items, default_labels) | |
| self.view = ListGui(self, self.model.items, self.model.items2, | |
| main_title, sub_title) | |
| def process(self, listbox_item): | |
| self.view.entry_vars[0].set(listbox_item) | |
| print(self.view.entry_vars[0]) | |
| print(listbox_item) | |
| def collect_entries(self): | |
| entry_data = dict() | |
| for index, entry_var in enumerate(self.view.entry_vars): | |
| print("{} : {}".format(self.model.items2[index], | |
| entry_var.get())) | |
| entry_data[self.model.items2[index]] = entry_var.get() | |
| print() | |
| print(entry_data) | |
| def run(self): | |
| self.view.run() | |
| class Model(object): | |
| def __init__(self, items, items2): | |
| self.items = items | |
| self.items2 = items2 | |
| def main(): | |
| try: | |
| Controller(name).run() | |
| except NameError: | |
| Controller('kunden').run() | |
| # Auswahl: kunden, lieferanten, produktdaten | |
| if __name__ == '__main__': | |
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| import tkinter as tk | |
| import gui_listbox_work as app_lbox | |
| CONFIG = { | |
| 'width' : 0, | |
| 'title' : "officeplanet", | |
| 'start_font': ('NimbusSansL', 80), # Startfenster | |
| 'big_font': ('NimbusSansL', 14), # Buttons, Texteingabe | |
| 'txt_font': ('NimbusSansL', 12), # Textausgabe | |
| 'txt_bground': 'grey', # Texteingabe, Textfenster, Buttons | |
| 'font_color': 'black', | |
| 'back_ground' : 'orange' | |
| } | |
| class View(object): | |
| def __init__(self, controller, conf): | |
| self.root = tk.Tk() | |
| self.root.title(conf['title']) | |
| self.controller = controller | |
| self.conf = conf | |
| xpos = 0 | |
| ypos = 0 | |
| screenx = self.root.winfo_screenwidth() | |
| screeny = self.root.winfo_screenheight() | |
| self.root.geometry("%dx%d+%d+%d" % (screenx, screeny, xpos, ypos)) | |
| self.frame = tk.Frame(self.root) | |
| self.frame.pack(side='top', fill='both', expand=True) | |
| self.label_button = tk.Label(self.frame, width=18, | |
| height=screeny, bg=self.conf['back_ground']) | |
| self.label_button.pack(side='left', fill='both') | |
| self.button = tk.Button(self.label_button, width=10, | |
| text='Kunden', bg=conf['txt_bground'], | |
| font=(conf['big_font']), fg=conf['font_color'], | |
| command=(lambda: app_lbox.Controller('kunden').run()) | |
| ).pack(padx=8, ipady=2, pady=19, fill='both') | |
| self.button2 = tk.Button(self.label_button, width=10, | |
| text='Lieferanten', bg=conf['txt_bground'], | |
| font=(conf['big_font']), fg=conf['font_color'], | |
| command=(lambda: app_lbox.Controller('lieferanten').run()) | |
| ).pack(padx=8, ipady=2, pady=19, fill='both') | |
| self.button3 = tk.Button(self.label_button, width=10, | |
| text='Produktdaten', bg=conf['txt_bground'], | |
| font=(conf['big_font']), fg=conf['font_color'], | |
| command=(lambda: app_lbox.Controller('produktdaten').run()) | |
| ).pack(padx=8, ipady=2, pady=19, fill='both') | |
| def run(self): | |
| self.frame.mainloop() | |
| class Controller(object): | |
| def __init__(self): | |
| self.view = View(self, CONFIG) | |
| def run(self): | |
| self.view.run() | |
| def main(): | |
| Controller().run() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment