Auslagern der Scrollbar-Funktion und Einfügen von Beispielbildern

This commit is contained in:
Max Sponsel 2020-09-12 11:45:49 +02:00
parent f176685f0b
commit 30d0e61ca7
8 changed files with 68 additions and 60 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
Beispielbilder/farbrad.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

View File

@ -5,6 +5,7 @@ from tkinter import filedialog, messagebox
import cv2 import cv2
import numpy as np import numpy as np
from Farbaenderung import gammaCorrection, reverseGammaCorrection from Farbaenderung import gammaCorrection, reverseGammaCorrection
from Scrollbar import ScrollFrame
root = tk.Tk() root = tk.Tk()
simGrad = tk.IntVar(root) simGrad = tk.IntVar(root)
@ -66,64 +67,6 @@ class Dyschromasie:
return self.sim_image return self.sim_image
class AutoScrollbar(tk.Scrollbar):
# A scrollbar that hides itself if it's not needed.
# Only works if you use the grid geometry manager!
def set(self, lo, hi):
if float(lo) <= 0.0 and float(hi) >= 1.0:
# grid_remove is currently missing from Tkinter!
self.tk.call("grid", "remove", self)
else:
self.grid()
tk.Scrollbar.set(self, lo, hi)
def pack(self, **kw):
raise TclError("cannot use pack with this widget")
def place(self, **kw):
raise TclError("cannot use place with this widget")
class ScrollFrame:
def __init__(self, master):
self.vscrollbar = AutoScrollbar(master)
self.vscrollbar.grid(row=0, column=1, sticky='ns')
self.hscrollbar = AutoScrollbar(master, orient='horizontal')
self.hscrollbar.grid(row=1, column=0, sticky='ew')
self.canvas = tk.Canvas(master, yscrollcommand=self.vscrollbar.set,
xscrollcommand=self.hscrollbar.set)
self.canvas.grid(row=0, column=0, sticky='nsew')
self.vscrollbar.config(command=self.canvas.yview)
self.hscrollbar.config(command=self.canvas.xview)
# make the canvas expandable
master.grid_rowconfigure(0, weight=1)
master.grid_columnconfigure(0, weight=1)
# create frame inside canvas
self.frame = tk.Frame(self.canvas)
self.frame.rowconfigure(1, weight=1)
self.frame.columnconfigure(1, weight=1)
# update the frame
self.frame.bind("<Configure>", self.reset_scrollregion)
def reset_scrollregion(self, event):
self.canvas.configure(scrollregion=self.canvas.bbox('all'))
def update(self):
self.canvas.create_window(0, 0, anchor='nw', window=self.frame)
self.frame.update_idletasks()
self.canvas.config(scrollregion=self.canvas.bbox("all"))
if self.frame.winfo_reqwidth() != self.canvas.winfo_width():
# update the canvas's width to fit the inner frame
self.canvas.config(width = self.frame.winfo_reqwidth())
if self.frame.winfo_reqheight() != self.canvas.winfo_height():
# update the canvas's width to fit the inner frame
self.canvas.config(height = self.frame.winfo_reqheight())
root.title("Projekt Dyschromasie") root.title("Projekt Dyschromasie")
SB = ScrollFrame(root) SB = ScrollFrame(root)
@ -143,7 +86,7 @@ simulationsGradient.grid(column= 0, row = 1, columnspan=10)
def browse(): def browse():
# Auswahl des FilePaths # Auswahl des FilePaths
try: try:
path = tk.filedialog.askopenfilename(filetypes=[("Image File", '.jpg')]) path = tk.filedialog.askopenfilename(filetypes=[("Image File", '.jpg'),("Image File", '.png')])
im = Image.open(path) im = Image.open(path)
except: except:
tk.messagebox.showerror(title='Datenfehler', message='Kein Bild gefunden/ausgewählt') tk.messagebox.showerror(title='Datenfehler', message='Kein Bild gefunden/ausgewählt')
@ -161,6 +104,7 @@ def browse():
global img, rows, cols, kanaele global img, rows, cols, kanaele
img = cv2.imread(path) img = cv2.imread(path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
#img = cv2.GaussianBlur(img, (3, 3), 0)
rows, cols, kanaele = img.shape rows, cols, kanaele = img.shape

View File

@ -10,3 +10,8 @@ def reverseGammaCorrection(v_reverse):
return round(255 * (12.92 * v_reverse)) return round(255 * (12.92 * v_reverse))
elif v_reverse > 0.0031308: elif v_reverse > 0.0031308:
return round(255 * (1.055 * v_reverse ** 0.41666 - 0.055)) return round(255 * (1.055 * v_reverse ** 0.41666 - 0.055))

59
Code/Scrollbar.py Normal file
View File

@ -0,0 +1,59 @@
import tkinter as tk
from tkinter import filedialog, messagebox
class AutoScrollbar(tk.Scrollbar):
# A scrollbar that hides itself if it's not needed.
# Only works if you use the grid geometry manager!
def set(self, lo, hi):
if float(lo) <= 0.0 and float(hi) >= 1.0:
# grid_remove is currently missing from Tkinter!
self.tk.call("grid", "remove", self)
else:
self.grid()
tk.Scrollbar.set(self, lo, hi)
def pack(self, **kw):
raise TclError("cannot use pack with this widget")
def place(self, **kw):
raise TclError("cannot use place with this widget")
class ScrollFrame:
def __init__(self, master):
self.vscrollbar = AutoScrollbar(master)
self.vscrollbar.grid(row=0, column=1, sticky='ns')
self.hscrollbar = AutoScrollbar(master, orient='horizontal')
self.hscrollbar.grid(row=1, column=0, sticky='ew')
self.canvas = tk.Canvas(master, yscrollcommand=self.vscrollbar.set,
xscrollcommand=self.hscrollbar.set)
self.canvas.grid(row=0, column=0, sticky='nsew')
self.vscrollbar.config(command=self.canvas.yview)
self.hscrollbar.config(command=self.canvas.xview)
# make the canvas expandable
master.grid_rowconfigure(0, weight=1)
master.grid_columnconfigure(0, weight=1)
# create frame inside canvas
self.frame = tk.Frame(self.canvas)
self.frame.rowconfigure(1, weight=1)
self.frame.columnconfigure(1, weight=1)
# update the frame
self.frame.bind("<Configure>", self.reset_scrollregion)
def reset_scrollregion(self, event):
self.canvas.configure(scrollregion=self.canvas.bbox('all'))
def update(self):
self.canvas.create_window(0, 0, anchor='nw', window=self.frame)
self.frame.update_idletasks()
self.canvas.config(scrollregion=self.canvas.bbox("all"))
if self.frame.winfo_reqwidth() != self.canvas.winfo_width():
# update the canvas's width to fit the inner frame
self.canvas.config(width = self.frame.winfo_reqwidth())
if self.frame.winfo_reqheight() != self.canvas.winfo_height():
# update the canvas's width to fit the inner frame
self.canvas.config(height = self.frame.winfo_reqheight())

Binary file not shown.