├── .gitignore ├── aspen.png ├── codemy.ico ├── color.py ├── radio.py ├── checkbox.py ├── popup.py ├── forget.py ├── open.py ├── pane.py ├── combo.py ├── hello.py ├── buttons.py ├── hide.py ├── new.py ├── menu.py ├── menu_frames.py ├── status.py ├── code.rb ├── flash2.py └── flash.py /.gitignore: -------------------------------------------------------------------------------- 1 | virt/ 2 | exe/ -------------------------------------------------------------------------------- /aspen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flatplanet/Intro-To-Tkinter/HEAD/aspen.png -------------------------------------------------------------------------------- /codemy.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flatplanet/Intro-To-Tkinter/HEAD/codemy.ico -------------------------------------------------------------------------------- /color.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import colorchooser 3 | 4 | root = Tk() 5 | root.title("Hello World!") 6 | root.geometry("400x400") 7 | root.iconbitmap('c:/guis/codemy.ico') 8 | 9 | def color(): 10 | my_color = colorchooser.askcolor()[1] 11 | my_label = Label(root, text=my_color).pack() 12 | my_label2 = Label(root, text="You Picked A Color!!", font=("Helvetica", 32), bg=my_color).pack() 13 | 14 | my_button = Button(root, text="Pick A Color", command=color).pack() 15 | 16 | 17 | root.mainloop() -------------------------------------------------------------------------------- /radio.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | root = Tk() 4 | root.title("Hello World!") 5 | root.geometry("400x400") 6 | root.iconbitmap('c:/guis/codemy.ico') 7 | 8 | # Create radio button function 9 | def radio(): 10 | if v.get() == "one": 11 | my_label = Label(root, text="You Clicked Radio Button One!") 12 | else: 13 | my_label = Label(root, text="You Clicked Radio Button Two!") 14 | 15 | my_label.pack(pady=10) 16 | 17 | 18 | # Radio Buttons 19 | v = StringVar() 20 | v.deselect() 21 | 22 | rbutton_1 = Radiobutton(root, text="One", variable=v, value="one").pack() 23 | rbutton_2 = Radiobutton(root, text="Two", variable=v, value="two").pack() 24 | 25 | my_button = Button(root, text="Click Me", command=radio) 26 | my_button.pack(pady=20) 27 | 28 | root.mainloop() -------------------------------------------------------------------------------- /checkbox.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | root = Tk() 4 | root.title("Hello World!") 5 | root.geometry("400x400") 6 | root.iconbitmap('c:/guis/codemy.ico') 7 | 8 | # Create toppings function 9 | def toppings(): 10 | if v.get() == "pepperoni": 11 | my_label = Label(root, text="You ordered pepperoni") 12 | else: 13 | my_label = Label(root, text="You don't want pepperoni") 14 | 15 | #my_label = Label(root, text=v.get()) 16 | my_label.pack(pady=10) 17 | 18 | # Check Boxes 19 | v = StringVar() 20 | 21 | my_check = Checkbutton(root, text="Pepperoni", variable=v, onvalue="pepperoni", offvalue="no_pepperoni") 22 | my_check.deselect() 23 | my_check.pack() 24 | 25 | my_button = Button(root, text="Select Toppings", command=toppings).pack(pady=10) 26 | 27 | 28 | root.mainloop() -------------------------------------------------------------------------------- /popup.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import messagebox 3 | 4 | root = Tk() 5 | root.title("Hello World!") 6 | root.geometry("400x400") 7 | root.iconbitmap('c:/guis/codemy.ico') 8 | 9 | # Create Popup function 10 | def popup(): 11 | response = messagebox.showinfo("Popup Title", "Look at my popup message!!") 12 | my_label = Label(root, text=response).pack(pady=10) 13 | 14 | ''' 15 | if response == 1: 16 | my_label = Label(root, text="you clicked yes!").pack(pady=10) 17 | else: 18 | my_label = Label(root, text="you clicked no!").pack(pady=10) 19 | ''' 20 | 21 | # Popup Boxes 22 | # showinfo, showwarning, showerror, askquestion, askokcancel, askyesno 23 | 24 | pop_button = Button(root, text="Click To Pop Up!", command=popup) 25 | pop_button.pack(pady=20) 26 | 27 | 28 | 29 | 30 | root.mainloop() -------------------------------------------------------------------------------- /forget.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from PIL import ImageTk, Image 3 | 4 | root = Tk() 5 | root.title("Hello World!") 6 | root.geometry("400x400") 7 | root.iconbitmap('c:/guis/codemy.ico') 8 | 9 | #hello_label = Label(root) 10 | 11 | #Submit Function 12 | def submit(): 13 | global hello_label 14 | clear() 15 | hello_label = Label(root, text="Hello " + e.get()) 16 | hello_label.grid(row=3, column=0) 17 | 18 | #Create clear function 19 | def clear(): 20 | hello_label.grid_forget() 21 | 22 | # Forget 23 | my_label = Label(root, text="Enter Your Name:").grid(row=0, column=0) 24 | 25 | e = Entry(root) 26 | e.grid(row=1, column=0) 27 | 28 | my_button = Button(root, text="Submit", command=submit).grid(row=2, column=0) 29 | 30 | clear_button = Button(root, text="Clear", command=clear).grid(row=2, column=1) 31 | 32 | root.mainloop() -------------------------------------------------------------------------------- /open.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from PIL import ImageTk, Image 3 | from tkinter import filedialog 4 | 5 | root = Tk() 6 | root.title("Hello World!") 7 | root.geometry("500x700") 8 | root.iconbitmap('c:/guis/codemy.ico') 9 | 10 | # Create open dialog box function 11 | def open_image(): 12 | #Open File Dialog Box 13 | root.filename = filedialog.askopenfilename(initialdir='/guis', title="Open An Image File", filetypes=( ("PNG File", "*.png"), ("All Files", "*.*") )) 14 | #my_label = Label(root, text=root.filename).pack(pady=10) 15 | global my_img 16 | # Open image and place on screen 17 | my_img = ImageTk.PhotoImage(Image.open(root.filename)) 18 | img_label = Label(root, image=my_img) 19 | img_label.pack(pady=10) 20 | 21 | 22 | my_button = Button(root, text="Open Image", command=open_image).pack(pady=10) 23 | 24 | 25 | root.mainloop() -------------------------------------------------------------------------------- /pane.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from PIL import ImageTk, Image 3 | 4 | root = Tk() 5 | root.geometry("400x400") 6 | 7 | 8 | pane1 = PanedWindow(bd=4, relief="raised", bg="red") 9 | pane1.pack(fill=BOTH, expand=1) 10 | 11 | left = Label(pane1, text="left pane") 12 | pane1.add(left) 13 | 14 | pane2 = PanedWindow(pane1, orient=VERTICAL, bd=4, relief="raised", bg="blue") 15 | pane1.add(pane2) 16 | 17 | top = Label(pane2, text="top pane") 18 | pane2.add(top) 19 | 20 | bottom = Label(pane2, text="bottom pane") 21 | pane2.add(bottom) 22 | 23 | ''' 24 | def new(): 25 | news = Toplevel() 26 | my_img = ImageTk.PhotoImage(Image.open("aspen.png")) 27 | my_label = Label(news, image=my_img) 28 | #my_label.image = my_img 29 | my_label.pack() 30 | 31 | 32 | news.mainloop() 33 | ''' 34 | 35 | #Button(root, text="Click", command=new).pack() 36 | mainloop() -------------------------------------------------------------------------------- /combo.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import ttk 3 | 4 | root = Tk() 5 | root.title("Hello World!") 6 | root.geometry("400x400") 7 | root.iconbitmap('c:/guis/codemy.ico') 8 | 9 | 10 | 11 | #Create Select function 12 | def select(): 13 | if my_combo.get() == "Monday": 14 | my_label = Label(root, text="You Clicked Monday!").pack(pady=10) 15 | if my_combo.get() == "Tuesday": 16 | my_label = Label(root, text="You Clicked Tuesday!").pack(pady=10) 17 | if my_combo.get() == "Wednesday": 18 | my_label = Label(root, text="You Clicked Wednesday!").pack(pady=10) 19 | 20 | # Combo Boxes 21 | options = [ 22 | "Monday", 23 | "Tuesday", 24 | "Wednesday", 25 | ] 26 | 27 | my_combo = ttk.Combobox(root, value=options) 28 | my_combo.current(0) 29 | my_combo.pack(pady=10) 30 | 31 | my_button = Button(root, text="Select", command=select).pack() 32 | 33 | 34 | 35 | root.mainloop() -------------------------------------------------------------------------------- /hello.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from PIL import ImageTk, Image 3 | 4 | root = Tk() 5 | root.title("Hello World!") 6 | root.geometry("400x900") 7 | root.iconbitmap('c:/guis/codemy.ico') 8 | 9 | # Create clicked function 10 | 11 | def clicked(): 12 | input = e.get() 13 | my_label2 = Label(root, text="Hello " + input) 14 | my_label2.pack() 15 | 16 | 17 | # Add Images 18 | my_image = ImageTk.PhotoImage(Image.open("aspen.png")) 19 | image_label = Label(image=my_image) 20 | image_label.pack() 21 | 22 | # Create labels 23 | my_label = Label(root, text='Enter Your Name:') 24 | my_label.pack() 25 | 26 | #Create Entry Widget Input Box 27 | e = Entry(root, font=("Helvetica", 18)) 28 | e.pack(pady=20) 29 | 30 | 31 | # Create Buttons 32 | my_button = Button(root, text="Click Me!", command=clicked) 33 | my_button.pack(pady=20) 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | root.mainloop() -------------------------------------------------------------------------------- /buttons.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | root = Tk() 4 | root.geometry("400x400") 5 | 6 | def show(): 7 | my_label = Label(root, text=v.get()).pack() 8 | 9 | #Radio 10 | v = StringVar() 11 | v.set("two") 12 | 13 | Radiobutton(root, text="One", variable=v, value="one").pack() 14 | Radiobutton(root, text="Two", variable=v, value="two").pack() 15 | 16 | my_button = Button(root, text="select", command=show).pack() 17 | 18 | 19 | #CheckBox ####################################################### 20 | 21 | def check(): 22 | label = Label(root, text=var.get()).pack() 23 | 24 | #var = IntVar() 25 | #c = Checkbutton(root, text="Expand", variable=var) 26 | #c.pack() 27 | 28 | var = StringVar() 29 | c = Checkbutton(root, text="Expand", variable=var, onvalue="pizza", offvalue="hello") 30 | c.deselect() 31 | c.pack() 32 | 33 | two_button = Button(root, text='check', command=check).pack() 34 | 35 | # POPUP############################### 36 | from tkinter import messagebox 37 | def pop(): 38 | messagebox.showinfo("Title", "Hello World!") 39 | 40 | pop_button = Button(root, text="Popup", command=pop).pack() 41 | 42 | mainloop() -------------------------------------------------------------------------------- /hide.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from PIL import ImageTk, Image 3 | 4 | root = Tk() 5 | root.title("Hello World!") 6 | root.geometry("400x400") 7 | root.iconbitmap('c:/guis/codemy.ico') 8 | 9 | # Create clicked function 10 | def clicked(): 11 | global my_label2 12 | input = e.get() 13 | my_label2 = Label(root, text="Hello " + input) 14 | my_label2.pack() 15 | 16 | # Hide Function 17 | def hide(): 18 | my_label2.pack_forget() 19 | #my_label2.destroy() 20 | 21 | # Show Function 22 | def show(): 23 | my_label2.pack() 24 | 25 | # Add Images 26 | #my_image = ImageTk.PhotoImage(Image.open("aspen.png")) 27 | #image_label = Label(image=my_image) 28 | #image_label.pack() 29 | 30 | # Create labels 31 | my_label = Label(root, text='Enter Your Name:') 32 | my_label.pack() 33 | 34 | #Create Entry Widget Input Box 35 | e = Entry(root, font=("Helvetica", 18)) 36 | e.pack(pady=20) 37 | 38 | 39 | # Create Buttons 40 | my_button = Button(root, text="Click Me!", command=clicked) 41 | my_button.pack(pady=20) 42 | 43 | hide_button = Button(root, text="Hide", command=hide) 44 | hide_button.pack(pady=20) 45 | 46 | show_button = Button(root, text="Show", command=show) 47 | show_button.pack(pady=20) 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | root.mainloop() -------------------------------------------------------------------------------- /new.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from PIL import ImageTk, Image 3 | 4 | root = Tk() 5 | root.title("Hello World!") 6 | root.geometry("400x400") 7 | root.iconbitmap('c:/guis/codemy.ico') 8 | 9 | # Create second window function 10 | def open_window(): 11 | new = Toplevel() 12 | new.title("Second Window") 13 | new.geometry("500x700") 14 | new.iconbitmap('c:/guis/codemy.ico') 15 | 16 | 17 | my_label = Label(new, text="Look at my fancy second window!").pack(pady=20) 18 | 19 | my_img = ImageTk.PhotoImage(Image.open("aspen.png")) 20 | img_label = Label(new, image=my_img) 21 | img_label.pack(pady=5) 22 | 23 | 24 | 25 | destroy_button = Button(new, text="Quit", command=new.destroy) 26 | destroy_button.pack(pady=5) 27 | 28 | # Minimize Original Window 29 | #hide_button = Button(new, text="Hide Main Window", command=root.iconify) 30 | #show_button = Button(new, text="Show Main Window", command=root.deiconify) 31 | 32 | # Withdraw Original Window 33 | hide_button = Button(new, text="Hide Main Window", command=root.withdraw) 34 | show_button = Button(new, text="Show Main Window", command=root.deiconify) 35 | 36 | kill_original = Button(new, text="Quit Original", command=root.destroy).pack() 37 | hide_button.pack() 38 | show_button.pack() 39 | 40 | new.mainloop() 41 | 42 | #Create New Windows 43 | my_button = Button(root, text="Open 2nd Window", command=open_window).pack() 44 | 45 | 46 | 47 | 48 | 49 | 50 | root.mainloop() -------------------------------------------------------------------------------- /menu.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | root = Tk() 4 | root.title("Hello World!") 5 | root.geometry("400x400") 6 | root.iconbitmap('c:/guis/codemy.ico') 7 | 8 | # Define our fake command 9 | def fake_command(): 10 | pass 11 | 12 | def hide(): 13 | my_frame.grid_forget() 14 | 15 | def show(): 16 | my_frame.grid(row=1, column=0, columnspan=2, padx=20, pady=20) 17 | 18 | #Define a Menu 19 | my_menu = Menu(root) 20 | root.config(menu=my_menu) 21 | 22 | #Create Menu Items 23 | file_menu = Menu(my_menu) 24 | my_menu.add_cascade(label="File", menu=file_menu) 25 | file_menu.add_command(label="New", command=fake_command) 26 | file_menu.add_separator() 27 | file_menu.add_command(label="Exit", command=root.quit) 28 | 29 | # Create another submenu Edit 30 | edit_menu = Menu(my_menu) 31 | my_menu.add_cascade(label="Edit", menu=edit_menu) 32 | edit_menu.add_command(label="Cut", command=fake_command) 33 | edit_menu.add_command(label="Copy", command=fake_command) 34 | edit_menu.add_command(label="Paste", command=fake_command) 35 | 36 | 37 | show_button = Button(root, text="Show", command=show) 38 | hide_button = Button(root, text="Hide", command=hide) 39 | 40 | show_button.grid(row=0, column=0) 41 | hide_button.grid(row=0, column=1) 42 | 43 | my_frame = Frame(root, width=200, height=200, bd=5, bg="blue", relief="sunken") 44 | my_frame.grid(row=1, column=0, columnspan=2, padx=20, pady=20) 45 | 46 | frame_label = Label(my_frame, text="Hello World!", font=("Helvetica", 20)) 47 | frame_label.pack(padx=20, pady=20) 48 | 49 | root.mainloop() -------------------------------------------------------------------------------- /menu_frames.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | root = Tk() 4 | root.title("Hello World!") 5 | #root.geometry("400x400") 6 | root.iconbitmap('c:/guis/codemy.ico') 7 | 8 | # Define our fake command 9 | def fake_command(): 10 | pass 11 | 12 | def new(): 13 | hide_menu_frames() 14 | file_frame.grid(row=1, column=0, columnspan=2, padx=20, pady=20) 15 | 16 | def cut(): 17 | hide_menu_frames() 18 | edit_frame.grid(row=1, column=0, columnspan=2, padx=20, pady=20) 19 | 20 | def hide_menu_frames(): 21 | edit_frame.grid_forget() 22 | file_frame.grid_forget() 23 | 24 | #Define a Menu 25 | my_menu = Menu(root) 26 | root.config(menu=my_menu) 27 | 28 | #Create Menu Items 29 | file_menu = Menu(my_menu) 30 | my_menu.add_cascade(label="File", menu=file_menu) 31 | file_menu.add_command(label="New", command=new) 32 | file_menu.add_separator() 33 | file_menu.add_command(label="Exit", command=root.quit) 34 | 35 | # Create another submenu Edit 36 | edit_menu = Menu(my_menu) 37 | my_menu.add_cascade(label="Edit", menu=edit_menu) 38 | edit_menu.add_command(label="Cut", command=cut) 39 | edit_menu.add_command(label="Copy", command=fake_command) 40 | edit_menu.add_command(label="Paste", command=fake_command) 41 | 42 | 43 | 44 | # File Menu Frame 45 | file_frame = Frame(root, width=400, height=400, bd=5, bg="blue", relief="sunken") 46 | #file_frame.grid(row=1, column=0, columnspan=2, padx=20, pady=20) 47 | 48 | file_frame_label = Label(file_frame, text="File Frame", font=("Helvetica", 20)) 49 | file_frame_label.pack(padx=20, pady=20) 50 | 51 | 52 | # Edit Menu Frame 53 | edit_frame = Frame(root, width=400, height=400, bd=5, bg="blue", relief="sunken") 54 | #file_frame.grid(row=1, column=0, columnspan=2, padx=20, pady=20) 55 | 56 | edit_frame_label = Label(edit_frame, text="Cut Frame", font=("Helvetica", 20)) 57 | edit_frame_label.pack(padx=20, pady=20) 58 | 59 | my_status = Label(root, text="Waiting", bd=2, relief="sunken", anchor=E, width=56) 60 | my_status.grid(row=2, column=0, sticky=S) 61 | 62 | root.mainloop() -------------------------------------------------------------------------------- /status.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | root = Tk() 4 | root.title("Hello World!") 5 | #root.geometry("400x400") 6 | root.iconbitmap('c:/guis/codemy.ico') 7 | 8 | # Define our fake command 9 | def fake_command(): 10 | pass 11 | 12 | def new(): 13 | hide_menu_frames() 14 | current_status.set("File Status") 15 | file_frame.grid(row=0, column=0, columnspan=2, padx=20, pady=20) 16 | 17 | def cut(): 18 | hide_menu_frames() 19 | current_status.set("Cut Status") 20 | edit_frame.grid(row=0, column=0, columnspan=2, padx=20, pady=20) 21 | 22 | def hide_menu_frames(): 23 | edit_frame.grid_forget() 24 | file_frame.grid_forget() 25 | 26 | #Define a Menu 27 | my_menu = Menu(root) 28 | root.config(menu=my_menu) 29 | 30 | #Create Menu Items 31 | file_menu = Menu(my_menu) 32 | my_menu.add_cascade(label="File", menu=file_menu) 33 | file_menu.add_command(label="New", command=new) 34 | file_menu.add_separator() 35 | file_menu.add_command(label="Exit", command=root.quit) 36 | 37 | # Create another submenu Edit 38 | edit_menu = Menu(my_menu) 39 | my_menu.add_cascade(label="Edit", menu=edit_menu) 40 | edit_menu.add_command(label="Cut", command=cut) 41 | edit_menu.add_command(label="Copy", command=fake_command) 42 | edit_menu.add_command(label="Paste", command=fake_command) 43 | 44 | 45 | 46 | # File Menu Frame 47 | file_frame = Frame(root, width=400, height=400, bd=5, bg="blue", relief="sunken") 48 | #file_frame.grid(row=1, column=0, columnspan=2, padx=20, pady=20) 49 | 50 | file_frame_label = Label(file_frame, text="File Frame", font=("Helvetica", 20)) 51 | file_frame_label.pack(padx=20, pady=20) 52 | 53 | 54 | # Edit Menu Frame 55 | edit_frame = Frame(root, width=400, height=400, bd=5, bg="blue", relief="sunken") 56 | #file_frame.grid(row=1, column=0, columnspan=2, padx=20, pady=20) 57 | 58 | edit_frame_label = Label(edit_frame, text="Cut Frame", font=("Helvetica", 20)) 59 | edit_frame_label.pack(padx=20, pady=20) 60 | 61 | current_status = StringVar() 62 | current_status.set("Waiting") 63 | 64 | my_status = Label(root, textvariable=current_status, bd=1, relief="sunken", width=56, anchor=E) 65 | my_status.grid(row=1, column=0) 66 | 67 | 68 | root.mainloop() -------------------------------------------------------------------------------- /code.rb: -------------------------------------------------------------------------------- 1 | coins = { 2 | "status"=> 3 | {"timestamp"=>"2020-03-12T23:16:38.645Z", "error_code"=>0, "error_message"=>nil, "elapsed"=>20, "credit_count"=>1, "notice"=>nil}, 4 | "data"=> 5 | [ 6 | {"id"=>1, "name"=>"Bitcoin", "symbol"=>"BTC", "slug"=>"bitcoin", "num_market_pairs"=>7787, "date_added"=>"2013-04-28T00:00:00.000Z", "tags"=>["mineable"], "max_supply"=>21000000, "circulating_supply"=>18267550, "total_supply"=>18267550, "platform"=>nil, "cmc_rank"=>1, "last_updated"=>"2020-03-12T23:15:37.000Z", "quote"=>{"USD"=>{"price"=>5626.52733697, "volume_24h"=>54481067695.9674, "percent_change_1h"=>-3.7353, "percent_change_24h"=>-28.7466, "percent_change_7d"=>-38.1037, "market_cap"=>102782869454.46632, "last_updated"=>"2020-03-12T23:15:37.000Z"}}}, 7 | {"id"=>1027, "name"=>"Ethereum", "symbol"=>"ETH", "slug"=>"ethereum", "num_market_pairs"=>5189, "date_added"=>"2015-08-07T00:00:00.000Z", "tags"=>["mineable"], "max_supply"=>nil, "circulating_supply"=>110070388.624, "total_supply"=>110070388.624, "platform"=>nil, "cmc_rank"=>2, "last_updated"=>"2020-03-12T23:16:23.000Z", "quote"=>{"USD"=>{"price"=>123.927059414, "volume_24h"=>22323695871.5295, "percent_change_1h"=>-6.08875, "percent_change_24h"=>-35.8541, "percent_change_7d"=>-46.3087, "market_cap"=>13640699590.728518, "last_updated"=>"2020-03-12T23:16:23.000Z"}}}, 8 | {"id"=>52, "name"=>"XRP", "symbol"=>"XRP", "slug"=>"xrp", "num_market_pairs"=>505, "date_added"=>"2013-08-04T00:00:00.000Z", "tags"=>[], "max_supply"=>100000000000, "circulating_supply"=>43818008717, "total_supply"=>99991068479, "platform"=>nil, "cmc_rank"=>3, "last_updated"=>"2020-03-12T23:16:05.000Z", "quote"=>{"USD"=>{"price"=>0.152615915608, "volume_24h"=>3566615655.76541, "percent_change_1h"=>-3.50385, "percent_change_24h"=>-26.4718, "percent_change_7d"=>-36.5461, "market_cap"=>6687325520.46428, "last_updated"=>"2020-03-12T23:16:05.000Z"}}}, 9 | {"id"=>825, "name"=>"Tether", "symbol"=>"USDT", "slug"=>"tether", "num_market_pairs"=>4230, "date_added"=>"2015-02-25T00:00:00.000Z", "tags"=>[], "max_supply"=>nil, "circulating_supply"=>4642367414, "total_supply"=>4776930644, "platform"=>{"id"=>83, "name"=>"Omni", "symbol"=>"OMNI", "slug"=>"omni", "token_address"=>"31"}, "cmc_rank"=>4, "last_updated"=>"2020-03-12T23:16:23.000Z", "quote"=>{"USD"=>{"price"=>1.01357130856, "volume_24h"=>73676047724.2449, "percent_change_1h"=>1.50293, "percent_change_24h"=>1.40821, "percent_change_7d"=>1.11414, "market_cap"=>4705370414.624283, "last_updated"=>"2020-03-12T23:16:23.000Z"}}}, 10 | {"id"=>1831, "name"=>"Bitcoin Cash", "symbol"=>"BCH", "slug"=>"bitcoin-cash", "num_market_pairs"=>457, "date_added"=>"2017-07-23T00:00:00.000Z", "tags"=>["mineable"], "max_supply"=>21000000, "circulating_supply"=>18327175, "total_supply"=>18327175, "platform"=>nil, "cmc_rank"=>5, "last_updated"=>"2020-03-12T23:16:07.000Z", "quote"=>{"USD"=>{"price"=>170.332627883, "volume_24h"=>5432071879.27866, "percent_change_1h"=>-2.67807, "percent_change_24h"=>-36.0769, "percent_change_7d"=>-49.5853, "market_cap"=>3121715879.4216204, "last_updated"=>"2020-03-12T23:16:07.000Z"}}}, 11 | {"id"=>3602, "name"=>"Bitcoin SV", "symbol"=>"BSV", "slug"=>"bitcoin-sv", "num_market_pairs"=>170, "date_added"=>"2018-11-09T00:00:00.000Z", "tags"=>["mineable"], "max_supply"=>21000000, "circulating_supply"=>18324439.5819233, "total_supply"=>18324439.5819233, "platform"=>nil, "cmc_rank"=>6, "last_updated"=>"2020-03-12T23:16:11.000Z", "quote"=>{"USD"=>{"price"=>120.117452219, "volume_24h"=>2565496264.82914, "percent_change_1h"=>-4.35163, "percent_change_24h"=>-37.0088, "percent_change_7d"=>-50.3106, "market_cap"=>2201084995.921624, "last_updated"=>"2020-03-12T23:16:11.000Z"}}}, 12 | {"id"=>2, "name"=>"Litecoin", "symbol"=>"LTC", "slug"=>"litecoin", "num_market_pairs"=>568, "date_added"=>"2013-04-28T00:00:00.000Z", "tags"=>["mineable"], "max_supply"=>84000000, "circulating_supply"=>64277999.6287857, "total_supply"=>64277999.6287857, "platform"=>nil, "cmc_rank"=>7, "last_updated"=>"2020-03-12T23:16:06.000Z", "quote"=>{"USD"=>{"price"=>32.7083079419, "volume_24h"=>5308398381.794, "percent_change_1h"=>-3.17079, "percent_change_24h"=>-32.2794, "percent_change_7d"=>-47.3207, "market_cap"=>2102424605.7476568, "last_updated"=>"2020-03-12T23:16:06.000Z"}}}, 13 | {"id"=>1765, "name"=>"EOS", "symbol"=>"EOS", "slug"=>"eos", "num_market_pairs"=>379, "date_added"=>"2017-07-01T00:00:00.000Z", "tags"=>[], "max_supply"=>nil, "circulating_supply"=>920874718.6528, "total_supply"=>1017574730.451, "platform"=>nil, "cmc_rank"=>8, "last_updated"=>"2020-03-12T23:16:05.000Z", "quote"=>{"USD"=>{"price"=>2.08918213266, "volume_24h"=>6732193375.60952, "percent_change_1h"=>-4.25482, "percent_change_24h"=>-31.4626, "percent_change_7d"=>-44.8165, "market_cap"=>1923875008.6277342, "last_updated"=>"2020-03-12T23:16:05.000Z"}}}, 14 | {"id"=>1839, "name"=>"Binance Coin", "symbol"=>"BNB", "slug"=>"binance-coin", "num_market_pairs"=>314, "date_added"=>"2017-07-25T00:00:00.000Z", "tags"=>[], "max_supply"=>187536713, "circulating_supply"=>155536713, "total_supply"=>187536713, "platform"=>nil, "cmc_rank"=>9, "last_updated"=>"2020-03-12T23:16:06.000Z", "quote"=>{"USD"=>{"price"=>10.9906812514, "volume_24h"=>470584867.85065, "percent_change_1h"=>-5.17427, "percent_change_24h"=>-32.8508, "percent_change_7d"=>-47.7565, "market_cap"=>1709454435.4734826, "last_updated"=>"2020-03-12T23:16:06.000Z"}}} 15 | ] 16 | } 17 | 18 | #puts coins['data'] 19 | 20 | #for x in @coins 21 | # for coin in my_coins 22 | # if coin == x["symbol"] 23 | # Name: price 24 | # Rank: Rank 25 | 26 | my_coins = ['BTC', 'XRP'] 27 | 28 | 29 | #for x in coins['data'] 30 | # x.each do |key,value| 31 | # puts "#{key}: #{value}" 32 | # end 33 | #end 34 | 35 | for x in coins['data'] 36 | for coin in my_coins 37 | if coin == x['symbol'] 38 | puts "#{x['name']}: #{x['quote']['USD']['price']}" 39 | end 40 | end 41 | end 42 | 43 | -------------------------------------------------------------------------------- /flash2.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from random import randint 3 | 4 | root = Tk() 5 | root.title("Flashcard App!") 6 | root.geometry("400x400") 7 | root.iconbitmap('c:/guis/exe/codemy.ico') 8 | 9 | # Create function to determine subtract answer correct? 10 | def subtract_correct(num1, num2): 11 | # Calculate the actual answer 12 | correct = num1 - num2 13 | 14 | # Correct and incorrect message 15 | output_answer_correct = StringVar() 16 | output_answer_incorrect = StringVar() 17 | output_answer_correct.set("Correct " + str(num1) + " - " + str(num2) + " = " + str(correct)) 18 | output_answer_incorrect.set("Incorrect " + str(num1) + " - " + str(num2) + " = " + str(correct) + ", Not " + subtract_answer.get()) 19 | 20 | if int(subtract_answer.get()) == correct: 21 | subtract_correct_label.config(text=output_answer_correct.get()) 22 | else: 23 | subtract_correct_label.config(text=output_answer_incorrect.get()) 24 | 25 | # Clear the answer box 26 | subtract_answer.delete(0, 'end') 27 | 28 | # Generate two new random numbers 29 | num_1.set(randint(0,10)) 30 | num_2.set(randint(0,10)) 31 | subtract_flash.config(text=str(num_1.get()) + " - " + str(num_2.get()), font=("helvetica", 72)) 32 | 33 | #Create our subtractio function 34 | def subtract(): 35 | hide_menu_frames() 36 | subtract_frame.pack(fill="both", expand=1) 37 | 38 | # Create 2 random numbers 39 | global num_1 40 | global num_2 41 | num_1 = IntVar() 42 | num_2 = IntVar() 43 | num_1.set(randint(0,10)) 44 | num_2.set(randint(0,10)) 45 | 46 | 47 | # Put our random number onto the screen 48 | global subtract_flash 49 | subtract_flash = Label(subtract_frame, text=str(num_1.get()) + " - " + str(num_2.get()), font=("helvetica", 72)) 50 | subtract_flash.pack(pady=10) 51 | 52 | # Answer Box 53 | global subtract_answer 54 | subtract_answer = Entry(subtract_frame) 55 | subtract_answer.pack(pady=5) 56 | 57 | # Answer Button 58 | subtract_button = Button(subtract_frame, text="Answer", command=lambda: subtract_correct(num_1.get(), num_2.get())) 59 | subtract_button.pack(pady=5) 60 | 61 | # Correct or Incorrect Message 62 | global subtract_correct_label 63 | subtract_correct_label = Label(subtract_frame, text="") 64 | subtract_correct_label.pack(pady=5) 65 | 66 | 67 | # Create function to determine add answer correct? 68 | def add_correct(num1, num2): 69 | # Calculate the actual answer 70 | correct = num1 + num2 71 | 72 | # Correct and incorrect message 73 | output_answer_correct = StringVar() 74 | output_answer_incorrect = StringVar() 75 | output_answer_correct.set("Correct " + str(num1) + " + " + str(num2) + " = " + str(correct)) 76 | output_answer_incorrect.set("Incorrect " + str(num1) + " + " + str(num2) + " = " + str(correct) + ", Not " + add_answer.get()) 77 | 78 | if int(add_answer.get()) == correct: 79 | add_correct_label.config(text=output_answer_correct.get()) 80 | else: 81 | add_correct_label.config(text=output_answer_incorrect.get()) 82 | 83 | # Clear the answer box 84 | add_answer.delete(0, 'end') 85 | 86 | # Generate two new random numbers 87 | num_1.set(randint(0,10)) 88 | num_2.set(randint(0,10)) 89 | add_flash.config(text=str(num_1.get()) + " + " + str(num_2.get()), font=("helvetica", 72)) 90 | 91 | #Create our addition function 92 | def add(): 93 | hide_menu_frames() 94 | add_frame.pack(fill="both", expand=1) 95 | 96 | # Create 2 random numbers 97 | global num_1 98 | global num_2 99 | num_1 = IntVar() 100 | num_2 = IntVar() 101 | num_1.set(randint(0,10)) 102 | num_2.set(randint(0,10)) 103 | 104 | 105 | # Put our random number onto the screen 106 | global add_flash 107 | add_flash = Label(add_frame, text=str(num_1.get()) + " + " + str(num_2.get()), font=("helvetica", 72)) 108 | add_flash.pack(pady=10) 109 | 110 | # Answer Box 111 | global add_answer 112 | add_answer = Entry(add_frame) 113 | add_answer.pack(pady=5) 114 | 115 | # Answer Button 116 | add_button = Button(add_frame, text="Answer", command=lambda: add_correct(num_1.get(), num_2.get())) 117 | add_button.pack(pady=5) 118 | 119 | # Correct or Incorrect Message 120 | global add_correct_label 121 | add_correct_label = Label(add_frame, text="") 122 | add_correct_label.pack(pady=5) 123 | 124 | 125 | 126 | 127 | # Create function to determine multiply answer correct? 128 | def multiply_correct(num1, num2): 129 | # Calculate the actual answer 130 | correct = num1 * num2 131 | 132 | # Correct and incorrect message 133 | output_answer_correct = StringVar() 134 | output_answer_incorrect = StringVar() 135 | output_answer_correct.set("Correct " + str(num1) + " * " + str(num2) + " = " + str(correct)) 136 | output_answer_incorrect.set("Incorrect " + str(num1) + " * " + str(num2) + " = " + str(correct) + ", Not " + multiply_answer.get()) 137 | 138 | if int(multiply_answer.get()) == correct: 139 | multiply_correct_label.config(text=output_answer_correct.get()) 140 | else: 141 | multiply_correct_label.config(text=output_answer_incorrect.get()) 142 | 143 | # Clear the answer box 144 | multiply_answer.delete(0, 'end') 145 | 146 | # Generate two new random numbers 147 | num_1.set(randint(0,10)) 148 | num_2.set(randint(0,10)) 149 | multiply_flash.config(text=str(num_1.get()) + " * " + str(num_2.get()), font=("helvetica", 72)) 150 | 151 | #Create our multiply function 152 | def multiply(): 153 | hide_menu_frames() 154 | multiply_frame.pack(fill="both", expand=1) 155 | 156 | # Create 2 random numbers 157 | global num_1 158 | global num_2 159 | num_1 = IntVar() 160 | num_2 = IntVar() 161 | num_1.set(randint(0,10)) 162 | num_2.set(randint(0,10)) 163 | 164 | 165 | # Put our random number onto the screen 166 | global multiply_flash 167 | multiply_flash = Label(multiply_frame, text=str(num_1.get()) + " * " + str(num_2.get()), font=("helvetica", 72)) 168 | multiply_flash.pack(pady=10) 169 | 170 | # Answer Box 171 | global multiply_answer 172 | multiply_answer = Entry(multiply_frame) 173 | multiply_answer.pack(pady=5) 174 | 175 | # Answer Button 176 | multiply_button = Button(multiply_frame, text="Answer", command=lambda: multiply_correct(num_1.get(), num_2.get())) 177 | multiply_button.pack(pady=5) 178 | 179 | # Correct or Incorrect Message 180 | global multiply_correct_label 181 | multiply_correct_label = Label(multiply_frame, text="") 182 | multiply_correct_label.pack(pady=5) 183 | 184 | 185 | # Create function to determine division answer correct? 186 | def divide_correct(num1, num2): 187 | # Calculate the actual answer 188 | correct = num1 / num2 189 | 190 | # Correct and incorrect message 191 | output_answer_correct = StringVar() 192 | output_answer_incorrect = StringVar() 193 | output_answer_correct.set("Correct " + str(num1) + " / " + str(num2) + " = " + str(correct)) 194 | output_answer_incorrect.set("Incorrect " + str(num1) + " / " + str(num2) + " = " + str(correct) + ", Not " + divide_answer.get()) 195 | 196 | if float(divide_answer.get()) == correct: 197 | divide_correct_label.config(text=output_answer_correct.get()) 198 | else: 199 | divide_correct_label.config(text=output_answer_incorrect.get()) 200 | 201 | # Clear the answer box 202 | divide_answer.delete(0, 'end') 203 | 204 | # Generate two new random numbers 205 | num_1.set(randint(0,10)) 206 | num_2.set(randint(1,10)) 207 | divide_flash.config(text=str(num_1.get()) + " / " + str(num_2.get()), font=("helvetica", 72)) 208 | 209 | #Create our division function 210 | def divide(): 211 | hide_menu_frames() 212 | divide_frame.pack(fill="both", expand=1) 213 | 214 | # Create 2 random numbers 215 | global num_1 216 | global num_2 217 | num_1 = IntVar() 218 | num_2 = IntVar() 219 | num_1.set(randint(0,10)) 220 | num_2.set(randint(1,10)) 221 | 222 | 223 | # Put our random number onto the screen 224 | global divide_flash 225 | divide_flash = Label(divide_frame, text=str(num_1.get()) + " / " + str(num_2.get()), font=("helvetica", 72)) 226 | divide_flash.pack(pady=10) 227 | 228 | # Answer Box 229 | global divide_answer 230 | divide_answer = Entry(divide_frame) 231 | divide_answer.pack(pady=5) 232 | 233 | # Answer Button 234 | divide_button = Button(divide_frame, text="Answer", command=lambda: divide_correct(num_1.get(), num_2.get())) 235 | divide_button.pack(pady=5) 236 | 237 | # Correct or Incorrect Message 238 | global divide_correct_label 239 | divide_correct_label = Label(divide_frame, text="") 240 | divide_correct_label.pack(pady=5) 241 | 242 | 243 | 244 | # Hide Frame Function 245 | def hide_menu_frames(): 246 | for widget in add_frame.winfo_children(): 247 | widget.destroy() 248 | for widget in subtract_frame.winfo_children(): 249 | widget.destroy() 250 | for widget in multiply_frame.winfo_children(): 251 | widget.destroy() 252 | for widget in divide_frame.winfo_children(): 253 | widget.destroy() 254 | add_frame.pack_forget() 255 | subtract_frame.pack_forget() 256 | multiply_frame.pack_forget() 257 | divide_frame.pack_forget() 258 | start_frame.pack_forget() 259 | 260 | #Define Main Menu 261 | my_menu = Menu(root) 262 | root.config(menu=my_menu) 263 | 264 | # Create menu items 265 | math_menu = Menu(my_menu) 266 | my_menu.add_cascade(label="MathCards", menu=math_menu) 267 | math_menu.add_command(label="Add", command=add) 268 | math_menu.add_command(label="Subtract", command=subtract) 269 | math_menu.add_command(label="Multiply", command=multiply) 270 | math_menu.add_command(label="Divide", command=divide) 271 | math_menu.add_separator() 272 | math_menu.add_command(label="Exit", command=root.quit) 273 | 274 | # Create Math Frames 275 | add_frame = Frame(root, width=400, height=400) 276 | subtract_frame = Frame(root, width=400, height=400) 277 | multiply_frame = Frame(root, width=400, height=400) 278 | divide_frame = Frame(root, width=400, height=400) 279 | 280 | start_frame = Frame(root, width=400, height=400) 281 | start_frame.pack(fill="both", expand=1) 282 | 283 | start_label = Label(start_frame, text="Welcome To Math Flashcards!", font=("Helvetica", 18)).pack(pady=50) 284 | 285 | a_button = Button(start_frame, text="Addition Flashcards", command=add).pack(pady=5) 286 | s_button = Button(start_frame, text="Subtraction Flashcards", command=subtract).pack(pady=5) 287 | m_button = Button(start_frame, text="Multiplication Flashcards", command=multiply).pack(pady=5) 288 | d_button = Button(start_frame, text="Division Flashcards", command=divide).pack(pady=5) 289 | 290 | root.mainloop() -------------------------------------------------------------------------------- /flash.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from random import randint 3 | 4 | root = Tk() 5 | root.title("Flashcard App!") 6 | root.geometry("400x400") 7 | root.iconbitmap('c:/guis/exe/codemy.ico') 8 | 9 | 10 | 11 | # Create function to determine subtract answer correct? 12 | def subtract_correct(num1, num2): 13 | # Calculate the actual answer 14 | correct = num1 - num2 15 | 16 | # Correct and incorrect message 17 | output_answer_correct = StringVar() 18 | output_answer_incorrect = StringVar() 19 | output_answer_correct.set("Correct " + str(num1) + " - " + str(num2) + " = " + str(correct)) 20 | output_answer_incorrect.set("Incorrect " + str(num1) + " - " + str(num2) + " = " + str(correct) + ", Not " + subtract_answer.get()) 21 | 22 | if int(subtract_answer.get()) == correct: 23 | subtract_correct_label.config(text=output_answer_correct.get()) 24 | else: 25 | subtract_correct_label.config(text=output_answer_incorrect.get()) 26 | 27 | # Clear the answer box 28 | subtract_answer.delete(0, 'end') 29 | 30 | # Generate two new random numbers 31 | num_1.set(randint(0,10)) 32 | num_2.set(randint(0,10)) 33 | subtract_flash.config(text=str(num_1.get()) + " - " + str(num_2.get()), font=("helvetica", 72)) 34 | 35 | #Create our subtractio function 36 | def subtract(): 37 | hide_menu_frames() 38 | subtract_frame.pack(fill="both", expand=1) 39 | 40 | # Create 2 random numbers 41 | global num_1 42 | global num_2 43 | num_1 = IntVar() 44 | num_2 = IntVar() 45 | num_1.set(randint(0,10)) 46 | num_2.set(randint(0,10)) 47 | 48 | 49 | # Put our random number onto the screen 50 | global subtract_flash 51 | subtract_flash = Label(subtract_frame, text=str(num_1.get()) + " - " + str(num_2.get()), font=("helvetica", 72)) 52 | subtract_flash.pack(pady=10) 53 | 54 | # Answer Box 55 | global subtract_answer 56 | subtract_answer = Entry(subtract_frame) 57 | subtract_answer.pack(pady=5) 58 | 59 | # Answer Button 60 | subtract_button = Button(subtract_frame, text="Answer", command=lambda: subtract_correct(num_1.get(), num_2.get())) 61 | subtract_button.pack(pady=5) 62 | 63 | # Correct or Incorrect Message 64 | global subtract_correct_label 65 | subtract_correct_label = Label(subtract_frame, text="") 66 | subtract_correct_label.pack(pady=5) 67 | 68 | 69 | # Create function to determine add answer correct? 70 | def add_correct(num1, num2): 71 | # Calculate the actual answer 72 | correct = num1 + num2 73 | 74 | # Correct and incorrect message 75 | output_answer_correct = StringVar() 76 | output_answer_incorrect = StringVar() 77 | output_answer_correct.set("Correct " + str(num1) + " + " + str(num2) + " = " + str(correct)) 78 | output_answer_incorrect.set("Incorrect " + str(num1) + " + " + str(num2) + " = " + str(correct) + ", Not " + add_answer.get()) 79 | 80 | if int(add_answer.get()) == correct: 81 | add_correct_label.config(text=output_answer_correct.get()) 82 | else: 83 | add_correct_label.config(text=output_answer_incorrect.get()) 84 | 85 | # Clear the answer box 86 | add_answer.delete(0, 'end') 87 | 88 | # Generate two new random numbers 89 | num_1.set(randint(0,10)) 90 | num_2.set(randint(0,10)) 91 | add_flash.config(text=str(num_1.get()) + " + " + str(num_2.get()), font=("helvetica", 72)) 92 | 93 | #Create our addition function 94 | def add(): 95 | hide_menu_frames() 96 | add_frame.pack(fill="both", expand=1) 97 | 98 | # Create 2 random numbers 99 | global num_1 100 | global num_2 101 | num_1 = IntVar() 102 | num_2 = IntVar() 103 | num_1.set(randint(0,10)) 104 | num_2.set(randint(0,10)) 105 | 106 | 107 | # Put our random number onto the screen 108 | global add_flash 109 | add_flash = Label(add_frame, text=str(num_1.get()) + " + " + str(num_2.get()), font=("helvetica", 72)) 110 | add_flash.pack(pady=10) 111 | 112 | # Answer Box 113 | global add_answer 114 | add_answer = Entry(add_frame) 115 | add_answer.pack(pady=5) 116 | 117 | # Answer Button 118 | add_button = Button(add_frame, text="Answer", command=lambda: add_correct(num_1.get(), num_2.get())) 119 | add_button.pack(pady=5) 120 | 121 | # Correct or Incorrect Message 122 | global add_correct_label 123 | add_correct_label = Label(add_frame, text="") 124 | add_correct_label.pack(pady=5) 125 | 126 | 127 | 128 | 129 | # Create function to determine multiply answer correct? 130 | def multiply_correct(num1, num2): 131 | # Calculate the actual answer 132 | correct = num1 * num2 133 | 134 | # Correct and incorrect message 135 | output_answer_correct = StringVar() 136 | output_answer_incorrect = StringVar() 137 | output_answer_correct.set("Correct " + str(num1) + " * " + str(num2) + " = " + str(correct)) 138 | output_answer_incorrect.set("Incorrect " + str(num1) + " * " + str(num2) + " = " + str(correct) + ", Not " + multiply_answer.get()) 139 | 140 | if int(multiply_answer.get()) == correct: 141 | multiply_correct_label.config(text=output_answer_correct.get()) 142 | else: 143 | multiply_correct_label.config(text=output_answer_incorrect.get()) 144 | 145 | # Clear the answer box 146 | multiply_answer.delete(0, 'end') 147 | 148 | # Generate two new random numbers 149 | num_1.set(randint(0,10)) 150 | num_2.set(randint(0,10)) 151 | multiply_flash.config(text=str(num_1.get()) + " * " + str(num_2.get()), font=("helvetica", 72)) 152 | 153 | #Create our multiply function 154 | def multiply(): 155 | hide_menu_frames() 156 | multiply_frame.pack(fill="both", expand=1) 157 | 158 | # Create 2 random numbers 159 | global num_1 160 | global num_2 161 | num_1 = IntVar() 162 | num_2 = IntVar() 163 | num_1.set(randint(0,10)) 164 | num_2.set(randint(0,10)) 165 | 166 | 167 | # Put our random number onto the screen 168 | global multiply_flash 169 | multiply_flash = Label(multiply_frame, text=str(num_1.get()) + " * " + str(num_2.get()), font=("helvetica", 72)) 170 | multiply_flash.pack(pady=10) 171 | 172 | # Answer Box 173 | global multiply_answer 174 | multiply_answer = Entry(multiply_frame) 175 | multiply_answer.pack(pady=5) 176 | 177 | # Answer Button 178 | multiply_button = Button(multiply_frame, text="Answer", command=lambda: multiply_correct(num_1.get(), num_2.get())) 179 | multiply_button.pack(pady=5) 180 | 181 | # Correct or Incorrect Message 182 | global multiply_correct_label 183 | multiply_correct_label = Label(multiply_frame, text="") 184 | multiply_correct_label.pack(pady=5) 185 | 186 | 187 | # Create function to determine division answer correct? 188 | def divide_correct(num1, num2): 189 | # Calculate the actual answer 190 | correct = num1 / num2 191 | 192 | # Correct and incorrect message 193 | output_answer_correct = StringVar() 194 | output_answer_incorrect = StringVar() 195 | output_answer_correct.set("Correct " + str(num1) + " / " + str(num2) + " = " + str(correct)) 196 | output_answer_incorrect.set("Incorrect " + str(num1) + " / " + str(num2) + " = " + str(correct) + ", Not " + divide_answer.get()) 197 | 198 | if float(divide_answer.get()) == correct: 199 | divide_correct_label.config(text=output_answer_correct.get()) 200 | else: 201 | divide_correct_label.config(text=output_answer_incorrect.get()) 202 | 203 | # Clear the answer box 204 | divide_answer.delete(0, 'end') 205 | 206 | # Generate two new random numbers 207 | num_1.set(randint(0,10)) 208 | num_2.set(randint(1,10)) 209 | divide_flash.config(text=str(num_1.get()) + " / " + str(num_2.get()), font=("helvetica", 72)) 210 | 211 | #Create our division function 212 | def divide(): 213 | hide_menu_frames() 214 | divide_frame.pack(fill="both", expand=1) 215 | 216 | # Create 2 random numbers 217 | global num_1 218 | global num_2 219 | num_1 = IntVar() 220 | num_2 = IntVar() 221 | num_1.set(randint(0,10)) 222 | num_2.set(randint(1,10)) 223 | 224 | 225 | # Put our random number onto the screen 226 | global divide_flash 227 | divide_flash = Label(divide_frame, text=str(num_1.get()) + " / " + str(num_2.get()), font=("helvetica", 72)) 228 | divide_flash.pack(pady=10) 229 | 230 | # Answer Box 231 | global divide_answer 232 | divide_answer = Entry(divide_frame) 233 | divide_answer.pack(pady=5) 234 | 235 | # Answer Button 236 | divide_button = Button(divide_frame, text="Answer", command=lambda: divide_correct(num_1.get(), num_2.get())) 237 | divide_button.pack(pady=5) 238 | 239 | # Correct or Incorrect Message 240 | global divide_correct_label 241 | divide_correct_label = Label(divide_frame, text="") 242 | divide_correct_label.pack(pady=5) 243 | 244 | 245 | 246 | # Hide Frame Function 247 | def hide_menu_frames(): 248 | # Destroy the children widgets in each frame 249 | for widget in add_frame.winfo_children(): 250 | widget.destroy() 251 | for widget in subtract_frame.winfo_children(): 252 | widget.destroy() 253 | for widget in multiply_frame.winfo_children(): 254 | widget.destroy() 255 | for widget in divide_frame.winfo_children(): 256 | widget.destroy() 257 | for widget in start_frame.winfo_children(): 258 | widget.destroy() 259 | 260 | # Hide all frames 261 | add_frame.pack_forget() 262 | subtract_frame.pack_forget() 263 | multiply_frame.pack_forget() 264 | divide_frame.pack_forget() 265 | start_frame.pack_forget() 266 | 267 | 268 | # Start Screen 269 | def home(): 270 | hide_menu_frames() 271 | start_frame.pack(fill="both", expand=1) 272 | start_label = Label(start_frame, text="Welcome To Math Flashcards!", font=("Helvetica", 18)).pack(pady=40) 273 | #button to flashcards 274 | a_button = Button(start_frame, text="Addition Flashcards", command=add).pack(pady=5) 275 | s_button = Button(start_frame, text="Subtraction Flashcards", command=subtract).pack(pady=5) 276 | m_button = Button(start_frame, text="Multiplication Flashcards", command=multiply).pack(pady=5) 277 | d_button = Button(start_frame, text="Division Flashcards", command=divide).pack(pady=5) 278 | 279 | 280 | 281 | #Define Main Menu 282 | my_menu = Menu(root) 283 | root.config(menu=my_menu) 284 | 285 | # Create menu items 286 | math_menu = Menu(my_menu) 287 | my_menu.add_cascade(label="MathCards", menu=math_menu) 288 | math_menu.add_command(label="Add", command=add) 289 | math_menu.add_command(label="Subtract", command=subtract) 290 | math_menu.add_command(label="Multiply", command=multiply) 291 | math_menu.add_command(label="Divide", command=divide) 292 | math_menu.add_separator() 293 | math_menu.add_command(label="Home", command=home) 294 | math_menu.add_command(label="Exit", command=root.quit) 295 | 296 | # Create Math Frames 297 | add_frame = Frame(root, width=400, height=400) 298 | subtract_frame = Frame(root, width=400, height=400) 299 | multiply_frame = Frame(root, width=400, height=400) 300 | divide_frame = Frame(root, width=400, height=400) 301 | start_frame = Frame(root, width=400, height=400) 302 | 303 | # Show the start screen 304 | home() 305 | 306 | root.mainloop() --------------------------------------------------------------------------------