You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.6 KiB
131 lines
3.6 KiB
from tkinter import *
|
|
from tkinter import ttk
|
|
from tkinter import messagebox
|
|
from tkinter import filedialog
|
|
from PIL import ImageTk, Image
|
|
import os
|
|
|
|
###########
|
|
#VARIBALES#
|
|
###########
|
|
colorBackgroundRoot="#06283D"
|
|
|
|
########
|
|
#WINDOW#
|
|
########
|
|
root = Tk()
|
|
root.title("Icons and images")
|
|
root.attributes('-type', 'dialog')#https://stackoverflow.com/questions/35830851/how-to-make-tkinter-window-floating-in-i3-windowmanager
|
|
root.geometry("1000x1000")
|
|
root.config(bg=colorBackgroundRoot)
|
|
im = Image.open('/home/key/Documents/tkinter/icons/rocket-64x64.png')
|
|
photo = ImageTk.PhotoImage(im)
|
|
root.wm_iconphoto(True, photo)
|
|
|
|
|
|
#############
|
|
#DEFINITIONS#
|
|
#############
|
|
|
|
|
|
pizza = StringVar()
|
|
pizza.set(0)
|
|
|
|
RADIO = [
|
|
("Pepperoni","Pepperoni"),
|
|
("Cheese","Cheese"),
|
|
("Mushroom","Mushroom"),
|
|
("Onion","Onion"),
|
|
]
|
|
|
|
################
|
|
#IMAGES & ICONS#
|
|
################
|
|
global myImage
|
|
myImage = ImageTk.PhotoImage(Image.open("/home/key/Documents/tkinter/icons/rocket-64x64.png"))
|
|
|
|
###########
|
|
#FUNCTIONS#
|
|
###########
|
|
def myClick():
|
|
clicText = "Label 1 Entry is: " + myEntry.get()
|
|
myCLickLabel = Label(root, text=clicText)
|
|
myCLickLabel.grid(row=5, column=0)
|
|
|
|
def radioCLicked(selection):
|
|
radioSelection = Label(frameRadio,text=selection)
|
|
radioSelection.pack()
|
|
|
|
def popUpCLicked(): #showinfo, showwarning, showerror,askquestion,askokcancel, askyesno
|
|
response = messagebox.showinfo("This is my INFO popup", "FYI")
|
|
Label(framePopUp,text=response).pack()
|
|
|
|
def newWindowCLicked():
|
|
top = Toplevel()
|
|
image1 = Label(top, image=myImage)
|
|
top.title("The ROcket image")
|
|
image1.pack()
|
|
buttonKillNewWindow = Button(top, text="Quit Window", command=top.destroy)
|
|
buttonKillNewWindow.pack()
|
|
|
|
def openFileCLicked():
|
|
file = filedialog.askopenfile(initialdir="/home/key/Documents/tkinter/",title="Selec A file",filetypes=(("png files", "*.png"),("all Files","*.*")))
|
|
image1_name = Label(frameOpenFile, text=os.path.abspath(file.name)).pack()
|
|
myImage = ImageTk.PhotoImage(Image.open(os.path.abspath(file.name)))
|
|
myImageLabel = Label(frameOpenFile,image=myImage).pack()
|
|
|
|
|
|
########
|
|
#FRAMES#
|
|
########
|
|
frame = LabelFrame(root, text="Exit Frame", padx=50, pady=50)
|
|
frameRadio = LabelFrame(root, text="Radio Button Frame", padx=50, pady=50)
|
|
framePopUp = LabelFrame(root, text="Generate PopUp", padx=50, pady=50)
|
|
frameNewWindow = LabelFrame(root, text="Generate New Window", padx=50, pady=50)
|
|
frameOpenFile = LabelFrame(root, text="Open File", padx=50, pady=50)
|
|
|
|
#########
|
|
#WIDGETS#
|
|
#########
|
|
#Labels
|
|
label1 = Label(frame, text="Label")
|
|
|
|
|
|
#Buttons
|
|
buttonQuit = Button(frame, text="Exit", command=root.quit)
|
|
buttonPizza = Button(frameRadio, text="Get Ingedient", command=lambda: radioCLicked(pizza.get()))
|
|
buttonPopUp = Button(framePopUp, text="PopUp", command=lambda: popUpCLicked())
|
|
buttonNewWindow = Button(frameNewWindow, text="New Window", command=lambda: newWindowCLicked())
|
|
buttonOpenFile = Button(frameOpenFile, text="Open File", command=lambda: openFileCLicked())
|
|
|
|
for text, mode in RADIO:
|
|
Radiobutton(frameRadio, text=text, variable=pizza, value=mode).pack()
|
|
|
|
#Entry
|
|
|
|
###########
|
|
#PLACEMENT#
|
|
###########
|
|
frame.grid(row=0, column=0, padx=10, pady=10)
|
|
label1.grid(row=0, column=0)
|
|
buttonQuit.grid(row=1, column=0)
|
|
|
|
frameRadio.grid(row=0, column=1, padx=10, pady=10)
|
|
buttonPizza.pack()
|
|
|
|
framePopUp.grid(row=1, column=0, padx=10, pady=10)
|
|
buttonPopUp.pack()
|
|
|
|
frameNewWindow.grid(row=1, column=1, padx=10, pady=10)
|
|
buttonNewWindow.pack()
|
|
|
|
frameOpenFile.grid(row=1, column=2, padx=10, pady=10)
|
|
buttonOpenFile.pack()
|
|
############
|
|
#DISPLAYING#
|
|
############
|
|
|
|
#Showing on the screen and aranging them
|
|
#Main Loop Equivalent of our main();
|
|
root.mainloop()
|