I am creating a simple application using tkinter.ttk. I am creating one Image Viewer App but while creating the app I am getting some problem. Here is my code:
from tkinter import *
from tkinter.ttk import *
from PIL import Image, ImageTk
root = Tk()
root.title("Simple Image Viewer")
style = Style()
root.columnconfigure(0, weight=True)
root.rowconfigure(0, weight=True)
img1 = ImageTk.PhotoImage(Image.open("images/img_1.jpg"))
img2 = ImageTk.PhotoImage(Image.open("images/img_2.jpg"))
img3 = ImageTk.PhotoImage(Image.open("images/img_3.jpg"))
images = [img1, img2, img3]
img_idx = 0
def previous_image():
global lbl_img
global images
global img_idx
img_idx = img_idx - 1
if img_idx < 0:
img_idx = len(images) - 1
try:
lbl_img.configure(image=images[img_idx])
except IndexError:
img_idx = -1
lbl_img.configure(image=images[img_idx])
finally:
status.configure(text=f"{img_idx + 1} of {len(images)} images.")
btn_back = Button(text="<", command=previous_image)
def forward_image():
global lbl_img
global images
global img_idx
img_idx = img_idx + 1
try:
lbl_img.configure(image=images[img_idx])
except IndexError:
img_idx = 0
lbl_img.configure(image=images[img_idx])
finally:
status.configure(text=f"{img_idx + 1} of {len(images)} images.")
btn_forward = Button(text=">", command=forward_image)
lbl_img = Label(image=images[img_idx])
status = Label(root, text=f"{img_idx + 1} of {len(images)} images.", borderwidth=1,
relief=SUNKEN, anchor="e")
status.grid(row=2, column=0, columnspan=3, stick=W+E)
btn_exit = Button(text="Exit", command=root.quit)
btn_back.grid(row=0, column=0, stick=W)
lbl_img.grid(row=0, column=1)
btn_forward.grid(row=0, column=2, stick=E)
btn_exit.grid(row=1, column=1)
root.mainloop()
When I run this then it comes like this:
In small window
And when I maximize it: In maximize
It comes like this. In above picture you can see that the image is not coming properly in center. My pictures must be in exact center in both in small and big window. Please can any one help me to do that by seeing my program.
Thanks in advance
You can achieve this with grid you need to make sure that left and right get space, also up and down, but the middle gets no space. As an exampel:
import tkinter as tk
root = tk.Tk()
up = tk.Frame(root)
up.grid(column=0, row=0,columnspan=3,sticky='n')
s1 = tk.Label(up, text='spacer')
s1.pack()
left = tk.Frame(root)
b1 = tk.Button(left, text='B1')
left.grid(column=0,row=1,sticky='w')
b1.pack()
middle = tk.Frame(root)
middle.grid(column=1, row=1)
s2 = tk.Label(middle, text='spacer')
s2.pack()
down = tk.Frame(root)
qb = tk.Button(down, text='Exit', command= root.destroy)
down.grid(column=0, row=2,columnspan=3,sticky='s')
qb.pack()
right = tk.Frame(root)
right.grid(column=2,row=1,sticky='e')
b2 = tk.Button(right, text='B2')
b2.pack()
root.columnconfigure(0,weight=1) #left get space
root.columnconfigure(2,weight=1) #right get space
root.rowconfigure(0, weight=1) #up get space
root.rowconfigure(2, weight=1) #down get space
root.mainloop()
Ourput:
For detail information what weight does.
I think there are 2 solutions you can do for this.
When you are displaying your image onto the program you can do ....place(x=x_coord, y=y_coord, anchor=center) to make sure that the image is set and always is in the center of the program.
One tip is to set the resolution of the program at the very start and instead of using grids you can use coordinates and anchors which will place your buttons and images nicely (I think), I haven't tried it with images.
Another solution which will probably fix your problem is determining if you want your program to be full screen. If you want your program to stay in a nice small window like on your first reference you can prevent the user from resizing the window. When you are maximizing the window you have not made the image to resize as the window gets bigger so I'm sure this is fine to do. At the start of your program after you define root... root.resizable(0, 0). This will prevent the user from resizing the window.
I implemented what you said but the buttons for me it is not perfect. I want to put the buttons on top of the label, I don't want them on the side.it is posible?
import tkinter as tk
root = tk.Tk()
image_list = getfiles()
up = tk.Frame(root)
up.grid(column=0, row=0,columnspan=3,sticky='n')
s1 = tk.Label(up, text='spacer')
s1.pack()
left = tk.Frame(root)
b1 = tk.Button(left, text='B1')
left.grid(column=0,row=1,sticky='w')
b1.pack()
middle = tk.Frame(root)
middle.grid(column=1, row=1)
s2 = tk.Label(middle, text='spacer')
image = Image.open(image_list[current])
photo = ImageTk.PhotoImage(image)
s2['image'] = photo
s2.photo = photo
s2.pack()
down = tk.Frame(root)
qb = tk.Button(down, text='Exit', command= root.destroy)
down.grid(column=0, row=2,columnspan=3,sticky='s')
qb.pack()
right = tk.Frame(root)
right.grid(column=2,row=1,sticky='e')
b2 = tk.Button(right, text='B2')
b2.pack()
root.columnconfigure(0,weight=1) #left get space
root.columnconfigure(2,weight=1) #right get space
root.rowconfigure(0, weight=1) #up get space
root.rowconfigure(2, weight=1) #down get space
root.mainloop()
To put the button in the same place than a Image you need place()
label = Tkinter.Label(root, compound=Tkinter.TOP)
label.pack()
A=Tkinter.Button(root, text='Previous picture', command=lambda: move(-1))
A.place(relx=0, x=2, y=20,width=130,height=100)
B=Tkinter.Button(root, text='Next picture', command=lambda: move(+1))
B.place(relx=0, x=135, y=20,width=130,height=100)
C=Tkinter.Button(root, text='PRINT', command=root.quit)
C.place(relx=1, x=-130, y=20,width=130,height=100)
move(0)
root.update()
root.mainloop()
Related
I am making a random generator for my friends and I'm stuck trying to make a scroll down option. So if you generate more the window can show, a scroll down window should be possible. But I can't seem to get any to work. I've tried many online tutorials.
And my second issue with my code is that I can't clear the generated labels from the window. I got it working that it expands the window.
from cProfile import label
from pickle import FRAME
import random
import tkinter as tk
from tkinter import BOTH, DISABLED, LEFT, RIGHT, VERTICAL, Y, Frame, Label, filedialog, Text
import os
from tkinter import ttk
from tkinter.font import NORMAL
from tkinter.messagebox import YES
root = tk.Tk()
root.title('guesser')
#Pelin arvonta ohjelma !
def delete():
for child in root.children.values():
info = child.grid_info()
if info['column'] == 0:
child.grid_forget()
def arvonta():
global label
list1 = []
lista = ["Valorant","Rainbow","Vampire: The masquerade","Playerunknown's battlegrounds","Fortnite","Left 4 Dead 2","Counter strike Global offensive","Realm roayale","Black ops 1 zombies/multiplayer","Black ops 2 zombies/multiplayer","Black ops 3 zombies/multiplayer"]
numero = random.randint(0, 10)
hahmo = (lista[numero])
list1.append(hahmo)
for app in list1:
label = tk.Label(frame, text=app, bg="red",font=('Helvetica',20))
label.pack()
def valorant():
list2 = []
lista2 = ["Brimstone","Viper","Omen","Killjoy","Cypher","Sova","Sage","phoenix","Jett","Reyna","Raze","Raze","Breach","Skye","Yoru","Astra","Kay/o","Chamber","Neon","Fade"]
numero = random.randint(0, 19)
randomValorantagent=(lista2[numero])
list2.append(randomValorantagent)
for app in list2:
label = tk.Label(frame, text=app, bg="red",font=('Helvetica',20))
label.pack()
def quitter():
quit()
canvas = tk.Canvas(root,height=700,width=700,bg="#263D42")
canvas.pack(side=LEFT,fill=BOTH,expand=1)
frame = tk.Frame(root,bg="green")
frame.place(relwidth=0.8,relheight=0.8,relx=0.1,rely=0.1)
frame.pack(fill=BOTH,expand=1)
my_scrollbar = ttk.Scrollbar(frame, orient=VERTICAL, command=canvas.yview)
my_scrollbar.pack(side=RIGHT, fill=Y)
# Configure The Canvas
canvas.configure(yscrollcommand=my_scrollbar.set)
canvas.bind('<Configure>', lambda e: canvas.configure(scrollregion = canvas.bbox("all")))
# Create ANOTHER Frame INSIDE the Canvas
second_frame = Frame(canvas)
# Add that New frame To a Window In The Canvas
canvas.create_window((0,0), window=second_frame, anchor="nw")
#rlls the game
openfile = tk.Button(second_frame,text="Roll a game",padx=10,pady=5,fg="white",bg="#263D42", command=arvonta)
openfile.pack()
#rolls a valorant agent
valorantA = tk.Button(second_frame,text='Roll valorant agent',padx=10,pady=5,fg="white",bg="#263D42",command=valorant)
valorantA.pack()
# stops program
stop = tk.Button(second_frame,text="Quit",padx=10,pady=5,fg="white",bg="#263D42",command=quitter)
stop.pack()
# deletes all info from screen.
deletor = tk.Button(second_frame,text="delete info",padx=10,pady=5,fg="white",bg="#263D42",command=delete)
deletor.pack()
root.mainloop()```
The following does most of what you want. I wrote it some time ago to test Scrollbars because they are wonky IMHO
from tkinter import *
from functools import partial
class ButtonsTest:
def __init__(self):
self.top = Tk()
self.top.title("Click a button to remove")
self.top.geometry("425x200+50+50")
Label(self.top, text=" Click a button to remove it ",
bg="lightyellow", font=('DejaVuSansMono', 12)
).grid(row=0, sticky="nsew")
Button(self.top, text='Exit', bg="orange", width=9,
command=self.top.quit).grid(row=1,column=0,
sticky="nsew")
self.add_scrollbar()
self.button_dic = {}
self.buttons()
self.top.mainloop()
##-------------------------------------------------------------------
def add_scrollbar(self):
self.canv = Canvas(self.top, relief=SUNKEN)
self.canv.config(width=400, height=200)
self.top_frame = Frame(self.canv, height=100)
##---------- scrollregion has to be larger than canvas size
## otherwise it just stays in the visible canvas
self.canv.config(scrollregion=(0,0, 400, 500))
self.canv.config(highlightthickness=0)
ybar = Scrollbar(self.top, width=15, troughcolor="lightblue")
ybar.config(command=self.canv.yview)
## connect the two widgets together
self.canv.config(yscrollcommand=ybar.set)
ybar.grid(row=3, column=2, sticky="ns")
self.canv.grid(row=3, column=0)
self.canv.create_window(1,0, anchor=NW,
window=self.top_frame)
##-------------------------------------------------------------------
def buttons(self):
b_row=1
b_col=0
for but_num in range(1, 51):
## create a button and send the button's number to
## self.cb_handler when the button is pressed
b = Button(self.top_frame, text = str(but_num), width=5,
command=partial(self.cb_handler, but_num))
b.grid(row=b_row, column=b_col)
## dictionary key=button number --> button instance
self.button_dic[but_num] = b
b_col += 1
if b_col > 4:
b_col = 0
b_row += 1
##----------------------------------------------------------------
def cb_handler( self, cb_number ):
print("\ncb_handler", cb_number)
self.button_dic[cb_number].grid_forget()
##===================================================================
BT=ButtonsTest()
I'm trying to add a background image to my root window but it doesn't seem to be working for me. This is my code. I would like the background image to cover the whole window and place the labels on top of the background image.
from tkinter import *
from tkinter import messagebox
top = Tk()
textButton = Frame(top)
textButton.pack()
img = PhotoImage(file="bk.gif")
img = img.subsample(1, 1)
background = Label(top, image = img, bd=0)
background.pack()
background.image = img
name_label = Label(textButton, text="Username")
name_label.grid(row=1, sticky=W)
name_entry = Entry(textButton)## the Entry will let the user entre text inside the text box
name_entry.grid(row=1, column=1)
password_label = Label(textButton, text="Password")
password_label.grid(row=2, sticky=W)
password_entry = Entry(textButton, show="*")
password_entry.grid(row=2, column=1)
top.mainloop
You can use place to use an image as a background for other widgets. place doesn't affect the geometry of other widgets so you can use it with grid or pack.
The main think to keep in mind is that you should do this before creating other widgets so that it is lowest in the stacking order. That, or be sure to call lower on it, otherwise it will overlay the other widgets rather than underlay them.
With your code, just remove background.pack() and replace it with these two lines:
background.place(relx=.5, rely=.5, anchor="center")
background.lower()
You don't need to change anything else. The above centers the image. If you instead want the image to start in the upper-left corner you can do it like this:
background.place(x=0, y=0, anchor="nw")
You have to use background as parent for widgets to put them inside Label with background.
I remove Frame to make it simpler. And now I can use weight to automatically resize empty rows and columns around widgets so they will be in the center.
import tkinter as tk
top = tk.Tk()
top.geometry('250x250')
img = tk.PhotoImage(file="hal_9000.gif")
img = img.subsample(1, 1)
background = tk.Label(top, image=img, bd=0)
background.pack(fill='both', expand=True)
background.image = img
# resize empty rows, columns to put other elements in center
background.rowconfigure(0, weight=100)
background.rowconfigure(3, weight=100)
background.columnconfigure(0, weight=100)
background.columnconfigure(3, weight=100)
name_label = tk.Label(background, text="Username")
name_label.grid(row=1, column=1, sticky='news')
name_entry = tk.Entry(background)## the Entry will let the user entre text inside the text box
name_entry.grid(row=1, column=2)
password_label = tk.Label(background, text="Password")
password_label.grid(row=2, column=1, sticky='news')
password_entry = tk.Entry(background, show="*")
password_entry.grid(row=2, column=2)
top.mainloop()
Result:
As you see widgets have gray background which you can't remove. If you need text without gray background then you have to use Canvas with create_text() (and create_window() to put Entry)
Gif file (with HAL 9000) to test code:
I want to fit this frame with scrollbar(refer the provided image) in the black space present in the provided image. How do I do that. The frame should totally cover the black space.
The code for program.The image
from tkinter import *
from tkinter import ttk
C = Tk()
C.maxsize(1200, 750)
C.geometry("1200x750")
C.title("Mainscreen")
style = ttk.Style()
style.theme_use('clam')
BG = PhotoImage(file="Mainscreen bg.png")
ML = PhotoImage(file="Music_label.png")
BG_label = Label(C, image=BG, border=0)
BG_label.place(x=0, y=0)
style.configure("Vertical.TScrollbar", gripcount=0,
background="Cyan", darkcolor="gray6", lightcolor="LightGreen",
troughcolor="Turquoise4", bordercolor="gray6", arrowcolor="gray6",arrowsize=15)
wrapper1= LabelFrame(C, width="1600", height="100", background="gray6",bd=0)
mycanvas = Canvas(wrapper1,background="gray6",borderwidth=0, highlightthickness=0, width=700, height=600)
mycanvas.pack(side=LEFT, expand="false", padx=0)
yscrollbar = ttk.Scrollbar(wrapper1, orient="vertical",command=mycanvas.yview)
yscrollbar.pack(side=RIGHT, fill="y")
mycanvas.configure(yscrollcommand=yscrollbar.set)
mycanvas.bind('<Configure>',lambda e: mycanvas.configure(scrollregion=mycanvas.bbox("all")))
myframe = Frame(mycanvas)
mycanvas.create_window((0,0), window=myframe, anchor="n")
wrapper1.pack(side=RIGHT,expand="false", padx=0, pady=200)
for i in range(50):
Button(myframe, image=ML,bg="gray6",bd=0).pack()
mainloop()
EDIT:
Music_Label
Mainscreen bg
So after trying to understand the underlying problem for a while I have reached the conclusion, that the problem is with the fact that the button are being drawn in the myframe and the myframe is outside the mycanvas which contains the scrollbar. So by changing the master widget for the button from myframe to mycanvas, the problem gets fixed now the scrollbar is adjacent to the buttons. BUT, Also now the button r shifted the side since while packing the wrapper1, you did side = RIGHT, so I would also suggest that you use place here instead of pack, since pack depends on the space available and is not reliable if you are using a Background for your GUI and want the buttons within a portion of it.
I have changed the following lines -:
Button(mycanvas, image=ML,bg="gray6",bd=0).pack() # Changed to mycanvas from myframe
and
wrapper1.place(x = {YOUR X, WHERE THE BOX STARTS}, y = {YOUR Y, WHERE THE BOX STARTS}) # Use place instead..
You can use pack also, and change the padx and pady arguments but it will be tricky to get it to work always as expected.
The fixed code is this -:
from tkinter import *
from tkinter import ttk
C = Tk()
C.maxsize(1200, 750)
C.geometry("1200x750")
C.title("Mainscreen")
style = ttk.Style()
style.theme_use('clam')
BG = PhotoImage(file="Mainscreen bg.png")
ML = PhotoImage(file="Music_label.png")
BG_label = Label(C, image=BG, border=0)
BG_label.place(x=0, y=0)
style.configure("Vertical.TScrollbar", gripcount=0,
background="Cyan", darkcolor="gray6", lightcolor="LightGreen",
troughcolor="Turquoise4", bordercolor="gray6", arrowcolor="gray6",arrowsize=15)
wrapper1= LabelFrame(C, width="1600", height="100", background="gray6",bd=0)
mycanvas = Canvas(wrapper1,background="gray6",borderwidth=0, highlightthickness=0, width=700, height=600)
mycanvas.pack(side=LEFT, expand=False, padx=0)
yscrollbar = ttk.Scrollbar(wrapper1, orient="vertical",command=mycanvas.yview)
yscrollbar.pack(side=RIGHT, fill="y", expand = False)
mycanvas.configure(yscrollcommand=yscrollbar.set)
mycanvas.bind('<Configure>',lambda e: mycanvas.configure(scrollregion=mycanvas.bbox("all")))
myframe = Frame(mycanvas)
mycanvas.create_window((0,0), window=myframe, anchor="n")
wrapper1.pack(expand=True, padx=0, pady=200) # Use place instead
for i in range(50):
Button(mycanvas, image=ML,bg="gray6",bd=0).pack() # Change this to mycanvas from myframe
mainloop()
My code:
import tkinter as tk
root = tk.Tk()
for i in range(50):
for j in range(50):
tk.Button(height=1, width=2, bg='Blue').grid(row=j, column=i)
root.mainloop()
I can not see all of the buttons in the screen even when I maxmize the window. so I want to add an option to zoom out (all of the widgets will be smaller) so I can see all of them. How do I do that?
Example code:
import tkinter as tk
root = tk.Tk()
root.state('zoomed')
widgets_to_zoom_list = []
DEFAULT_SIZE = 50
def zoom(widget):
for every_widget in widgets_to_zoom_list:
every_widget.config(width=widget.get(), height=widget.get())
def main():
canvas = tk.Canvas(root)
frame = tk.Frame(canvas)
zoom_scale = tk.Scale(root, orient='vertical', from_=1, to=100)
zoom_scale.config(command=lambda args: zoom(zoom_scale))
zoom_scale.set(DEFAULT_SIZE)
pixel = tk.PhotoImage(width=1, height=1)
for i in range(50):
btn = tk.Button(frame, text=str(i + 1), bg='Blue', image=pixel, width=DEFAULT_SIZE, height=DEFAULT_SIZE, compound="c")
btn.grid(row=0, column=i)
widgets_to_zoom_list.append(btn)
canvas.create_window(0, 0, anchor='nw', window=frame)
# make sure everything is displayed before configuring the scroll region
canvas.update_idletasks()
canvas.configure(scrollregion=canvas.bbox('all'))
canvas.pack(fill='both', side='left', expand=True)
zoom_scale.pack(fill='y', side='right')
root.mainloop()
if __name__ == '__main__':
main()
From what i have been able to understand from your question, i think you want the window to be resizable in tkinter.
To allow a window to be resized by the user, we use the resizable function -:
root.resizable(height = True, width = True)
In this case the two args are height and width which help you customize if you only want the widget to be vertically resizable or only want it to be horizontally resizable.
Your code with this function added should look like this -:
import tkinter as tk
root = tk.Tk()
root.resizable(True, True) #Assuming you want both vertically and horizontally resizable window.
for i in range(50):
for j in range(50):
tk.Button(height=1, width=2, bg='Blue').grid(row=j, column=i)
root.mainloop()
I hope this will solve your problem.
And I also hope you are safe in this time of an ongoing pandemic.
I created a simple program using python to change picture Contrast,Brightness color and etc. First I just added one effect, and it worked well, I managed to link it with a Scaler. Then I tried to add multiple effect at once which I've also linked with scalers, but when I try to add multiple effects on the picture (e.g Contrast and brightness at the same time) I got a grey Screen, or just nothing happened to the picture.
from tkinter import *
from tkinter import ttk
from tkinter.filedialog import askopenfilename
from PIL import Image
from PIL import ImageEnhance
def main():
window = Tk()
window.geometry("400x290")
window.configure(background="#EBEBEB")
OpenB = ttk.Button(window, text="Import Photo")
OpenB.pack()
def onClickImport():
askimage = askopenfilename()
global img
img=Image.open(askimage)
OpenB.config(command=onClickImport)
window.mainloop()
window2 = Tk()
window2.geometry("400x290")
window2.configure(background="#EBEBEB")
DisplayButton=ttk.Button(window2,text="Show")
DisplayButton.pack()
ScalerContrast= ttk.Scale(window2, from_=1.0, to_=5.0)
ScalerContrast.pack()
ScalerBrightness = ttk.Scale(window2, from_=1.0, to_=5.0)
ScalerBrightness.pack()
ScalerColor = ttk.Scale(window2, from_=1, to_=100)
ScalerColor.pack()
ScalerSharpness = ttk.Scale(window2, from_=1, to_=100)
ScalerSharpness.pack()
textCon=Text(window2,width=8,height=1)
textCon.insert(END,"Contrast")
textCon.config(state=DISABLED)
textCon.configure(background="#EBEBEB")
textCon.configure(font="Roboto")
textCon.pack()
textBr=Text(window2,width=8,height=1)
textBr.insert(END,"Brightness")
textBr.config(state=DISABLED)
textBr.configure(background="#EBEBEB")
textBr.configure(font="Roboto")
textBr.pack()
textCor=Text(window2,width=8,height=1)
textCor.insert(END,"Color")
textCor.config(state=DISABLED)
textCor.configure(background="#EBEBEB")
textCor.configure(font="Roboto")
textCor.pack()
textSh=Text(window2,width=8,height=1)
textSh.insert(END,"Sharpness")
textSh.config(state=DISABLED)
textSh.configure(background="#EBEBEB")
textSh.configure(font="Roboto")
textSh.pack()
converter = ImageEnhance.Contrast(img)
converter1= ImageEnhance.Brightness(img)
converter2= ImageEnhance.Color(img)
converter3= ImageEnhance.Sharpness(img)
def onClickDisplay():
img2=converter.enhance(ScalerContrast.get()) and converter1.enhance(ScalerBrightness.get()) and\
converter2.enhance(ScalerColor.get()) and converter3.enhance(ScalerColor.get())
img2.show()
DisplayButton.config(command=onClickDisplay)
window2.mainloop()
if __name__=='__main__':
main()
Welcome to SO!
First of all, you don't have to use config for all your Buttons, Text widgets and so on - you can simply give all those options as arguments when you're creating a widget, e.g.
textCon = Text(window2, width=8, height=1, state=DISABLED, background="#EBEBEB", font="Roboto")
This makes your code shorter, simpler and faster.
What you're doing in onClickDisplay does not work for a simple reason. You are using and, which is a boolean operator, to try to make multiple things happen at once - which is not what and is about. This is how i would rewrite your code:
class CustomImageEnhancer()
def __init__(self):
def onClickImport():
askimg = fd.askopenfilename()
self.img = Image.open(askimage)
return self.img
def converted_image(img_a, contrast, brightness, color, sharpness):
contrast_converter = ImageEnhance.Contrast(img_a)
img_b = contrast_converter.enhance(contrast)
brightness_converter = ImageEnhance.Brightness(img_b)
img_c = brightness_converter.enhance(brightness)
color_converter = ImageEnhance.Color(img_c)
img_d = color_converter.enhance(color)
sharpness_converter = ImageEnhance.Sharpness(img_d)
img_final = sharpness_converter.enhance(sharpness)
return img_final
def onClickDisplay():
cont = ScalerContrast.get()
bright = ScalerBrightness.get()
col = ScalerColor.get()
sharp = ScalerSharpness.get()
img = self.img
new_img = converted_image(img, cont, bright, col, sharp)
new_img.show()
root = Tk()
OpenB = ttk.Button(root, text="Import Photo", command=onClickImport)
OpenB.pack()
DisplayButton=ttk.Button(root, text="Show", command=onClickDisplay)
ScalerContrast= ttk.Scale(root, from_=1.0, to_=5.0)
ScalerBrightness = ttk.Scale(root, from_=1.0, to_=5.0)
ScalerColor = ttk.Scale(root, from_=1, to_=100)
ScalerSharpness = ttk.Scale(root, from_=1, to_=100)
DisplayButton.pack()
ScalerContrast.pack()
ScalerBrightness.pack()
ScalerColor.pack()
ScalerSharpness.pack()
textCon=Text(root, width=8, height=1, state=DISABLED, background="#EBEBEB", font='Roboto')
textCon.insert(END, 'Contrast')
textCon.pack()
textBr=Text(root, width=8, height=1, state=DISABLED, background='#EBEBEB', font='Roboto')
textBr.insert(END, 'Brightness')
textBr.pack()
textCor=Text(root, width=8, height=1, state=DISABLED, background='#EBEBEB', font='Roboto')
textCor.insert(END, 'Color')
textCor.pack()
textSh=Text(root, width=8, height=1, state=DISABLED, background='#EBEBEB', font='Roboto')
textSh.insert(END, 'Color')
textSh.pack()
root.mainloop()
window=CustomImageEnhancer()
By defining a class, you can work around having to use global variables. Opening two windows is not necessary in your case, as you can just add the button for choosing the image file to your other window. I would recommend using place() instead of pack(), as it will allow you to define exact x and y coordinates for your different widgets inside the window, which will make it look more structured - pack simply places widgets one after another.