decided to switch to python

master
key 2 years ago
parent 87569a9628
commit ae48a9ed30

Binary file not shown.

@ -0,0 +1,162 @@
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from tkinter import filedialog
from PIL import ImageTk, Image
import sqlite3
import os
###########
#VARIBALES#
###########
colorBackgroundRoot="#06283D"
########
#WINDOW#
########
root = Tk()
root.title("Database Interface")
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)
#############
#DEFINITIONS#
#############
def dbSubmit():
#Connect to database
db = sqlite3.connect('address_book.db')
#Create Cursor
c = db.cursor()
c.execute("INSERT INTO addresses VALUES (:firstName, :lastName, :address, :city, :state, :zipCode)",
{
'firstName' : firstName.get(),
'lastName' : lastName.get(),
'address' : address.get(),
'city' : city.get(),
'state' : state.get(),
'zipCode' : zipCode.get()
})
#Save chnages to the database
db.commit()
#Close Connection
db.close()
# Clear the text Boxes
firstName.delete(0,END)
lastName.delete(0,END)
address.delete(0,END)
city.delete(0,END)
state.delete(0,END)
zipCode.delete(0,END)
def dbQuery():
#Connect to database
db = sqlite3.connect('address_book.db')
#Create Cursor
c = db.cursor()
c.execute("SELECT *, oid FROM addresses")
records = c.fetchall();
print(records)
print_records=''
for record in records:
print_records += str(record) + '\n'
labelQuery = Label(root, text=print_records)
labelQuery.grid(row=8, column=0, columnspan=2)
#Save chnages to the database
db.commit()
#Close Connection
db.close()
#########
#DATBASE#
#########
#Create Table
'''
c.execute("""CREATE TABLE addresses (
first_name text,
last_name text,
address text,
city text,
state text,
zipcode integer
)
""")
'''
################
#IMAGES & ICONS#
################
###########
#FUNCTIONS#
###########
########
#FRAMES#
########
#########
#WIDGETS#
#########
firstName = Entry(root,width=30)
lastName = Entry(root,width=30)
address = Entry(root,width=30)
city = Entry(root,width=30)
state = Entry(root,width=30)
zipCode = Entry(root,width=30)
firstNameLabel = Label(root,text="First Name: ")
lastNameLabel = Label(root,text="Last Name: ")
addressLabel = Label(root,text="Address: ")
cityLabel = Label(root,text="city: ")
stateLabel = Label(root,text="state: ")
zipCodeLabel = Label(root,text="Zip Code: ")
buttonSubmit = Button(root, text="add to db", command=dbSubmit)
buttonQuery = Button(root, text="request from db", command=dbQuery)
###########
#PLACEMENT#
###########
firstName.grid(row=0, column=1, padx=20)
firstNameLabel.grid(row=0, column=0)
lastName.grid(row=1, column=1, padx=20)
lastNameLabel.grid(row=1, column=0)
address.grid(row=2, column=1, padx=20)
addressLabel.grid(row=2, column=0)
city.grid(row=3, column=1, padx=20)
cityLabel.grid(row=3, column=0)
state.grid(row=4, column=1, padx=20)
stateLabel.grid(row=4, column=0)
zipCode.grid(row=5, column=1, padx=20)
zipCodeLabel.grid(row=5, column=0)
buttonSubmit.grid(row=6, column=0, columnspan=2, padx=10, pady=10, ipadx=100)
buttonQuery.grid(row=7, column=0, columnspan=2, padx=10, pady=10, ipadx=100)
############
#DISPLAYING#
############
#Showing on the screen and aranging them
#Main Loop Equivalent of our main();
root.mainloop()

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

@ -0,0 +1,63 @@
from tkinter import *
from tkinter import ttk
#This is tha main window usulayy called Root
root = Tk()
root.title("simple Calculator")
numButtonSizeX=10
numButtonSizeY=10
calcScreenSize=50
buttonPerRow=3
paddingX=10
paddingY=10
buttonPaddingX=50
buttonPaddingY=20
boderSize=5
#FUNCTIONS It doenst matter if this is before the decalaritions(PYthon Thing).
def buttonClick(number):
screen.insert(0,number)
# Creating a widget label
#Labels
#Buttons
button1 = Button(root, text="1", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(1))
button2 = Button(root, text="2", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(2))
button3 = Button(root, text="3", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(3))
button4 = Button(root, text="4", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(4))
button5 = Button(root, text="5", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(5))
button6 = Button(root, text="6", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(6))
button7 = Button(root, text="7", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(7))
button8 = Button(root, text="8", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(8))
button9 = Button(root, text="9", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(9))
button0 = Button(root, text="0", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(0))
buttonPlus = Button(root, text="+", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick())
buttonClear = Button(root, text="Clear", padx=buttonPaddingX*2,pady=buttonPaddingY, command=lambda: buttonClick())
buttonEqual = Button(root, text="=", padx=buttonPaddingX*2,pady=buttonPaddingY, command=lambda: buttonClick())
#Entry
screen = Entry(root, width=calcScreenSize, borderwidth=boderSize)
screen.grid(row=0, column=0, columnspan=buttonPerRow, padx=paddingX, pady=paddingY)
#Showing on the screen and aranging them
button1.grid(row=1, column=0)
button2.grid(row=1, column=1)
button3.grid(row=1, column=2)
button4.grid(row=2, column=0)
button5.grid(row=2, column=1)
button6.grid(row=2, column=2)
button7.grid(row=3, column=0)
button8.grid(row=3, column=1)
button9.grid(row=3, column=2)
button0.grid(row=4, column=0)
buttonClear.grid(row=4, column=1, columnspan=2)
buttonPlus.grid(row=5, column=0)
buttonEqual.grid(row=5, column=1, columnspan=2)
#Main Loop Equivalent of our main();
root.mainloop()

@ -0,0 +1,130 @@
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()

@ -0,0 +1,44 @@
from tkinter import *
from tkinter import ttk
#This is tha main window usulayy called Root
root = Tk()
root.title("simple Calculator")
numButtonSizeX=10;
numButtonSizeY=10;
calcScreenSize=50;
#FUNCTIONS It doenst matter if this is before the decalaritions(PYthon Thing).
def myClick():
clicText = "Label 1 Entry is: " + myEntry.get()
myCLickLabel = Label(root, text=clicText)
myCLickLabel.grid(row=5, column=0)
# Creating a widget label
#Labels
myLabel1 = Label(root, text="Label1")
myLabel2 = Label(root, text="Label2")
#Buttons
myButton1 = Button(root, text="do not press", state=DISABLED, padx=10,pady=10,fg="blue",bg="orange")
myButton2 = Button(root, text="do not press",command=myClick,fg="blue",bg="orange")
#Entry
myEntry = Entry(root, width=50)
myEntry.insert(0, "Isert Label one's Entry")
myEntry.grid(row=0, column=1)
#Showing on the screen and aranging them
myLabel1.grid(row=0, column=0)
myLabel2.grid(row=1, column=0)
myButton1.grid(row=3, column=0)
myButton2.grid(row=4, column=0)
#Main Loop Equivalent of our main();
root.mainloop()

@ -0,0 +1,25 @@
import mariadb
import sys
# Connect to MariaDB Platform
try:
conn = mariadb.connect(
user="root",
password="KyKvMdRt586591!*",
host="db.keydev.me",
port=3306,
database="minibase_projects"
)
except mariadb.Error as e:
print(f"Error connecting to MariaDB Platform: {e}")
sys.exit(1)
# Get Cursor
cur = conn.cursor()
cur.execute("SELECT name, description FROM project")
print(cur)
for (name, description) in cur:
print(f"Name : {name}, What: {description}")

@ -0,0 +1,9 @@
#!/bin/bash
sudo apt install python3
sudo apt install python3-pip
sudo apt install libmariadb3 libmariadb-dev
pip3 install mariadb --break-system-packages
pip3 install pillow --break-system-packages
Loading…
Cancel
Save