Advertisement
Guest User

Untitled

a guest
Mar 7th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.25 KB | None | 0 0
  1. import sqlite3
  2. from tkinter import *
  3. from tkinter import messagebox
  4. import tkinter
  5. from tkinter import ttk
  6. from tkinter import *
  7. from tkinter import messagebox
  8. import json
  9. import requests
  10. import os
  11. from tkcalendar import DateEntry
  12. from datetime import date
  13.  
  14.  
  15.  
  16.  
  17.  
  18. ###########################################################
  19.  
  20. #Database Connection
  21.  
  22. with sqlite3.connect('quit.db') as db:
  23.     c = db.cursor()
  24.  
  25. c.execute('CREATE TABLE IF NOT EXISTS user (username TEXT NOT NULL ,password TEXT NOT NULL);')
  26. db.commit()
  27. db.close()
  28.  
  29. #Login Class
  30.  
  31.  
  32.  
  33. class login:
  34.    
  35.     def __init__(self,master):
  36.        
  37.         # Window
  38.        
  39.         self.master = master
  40.        
  41.         # Some Usefull variables
  42.  
  43.         self.username = StringVar()
  44.         self.password = StringVar()
  45.         self.n_username = StringVar()
  46.         self.n_password = StringVar()
  47.        
  48.         #Create Widgets
  49.  
  50.         self.widgets()
  51.  
  52.        
  53.     #Login Function
  54.  
  55.     def login(self):
  56.  
  57.         #Establish Connection
  58.        
  59.         with sqlite3.connect('quit.db') as db:
  60.             c = db.cursor()
  61.  
  62.         #Find user If there is any take proper action
  63.  
  64.         find_user = ('SELECT * FROM user WHERE username = ? and password = ?')
  65.         c.execute(find_user,[(self.username.get()),(self.password.get())])
  66.         result = c.fetchall()
  67.        
  68.         if result:
  69.  
  70.             self.logf.pack_forget()
  71.             self.head.pack_forget()
  72.             miLabel3 = Label(text="DASHBOARD", font=("Lucida Console", 18), background="gray")
  73.             miLabel3.pack()
  74.  
  75.  
  76.             #----Precio BTC en el index-----#
  77.  
  78.  
  79.             def draw():
  80.  
  81.                 global text
  82.                 frame=tkinter.Frame(root, width=50, height=20, relief='solid', bd=1,)
  83.                 frame.place(x=10,y=10)
  84.                 root["bg"] = "black"
  85.                 root["width"] = 100
  86.                 root["height"] = 20
  87.                 text=tkinter.Label(frame,text='Ticker', font=("Lucida Console", 8, "bold"), background="black", foreground="magenta1")
  88.                 text.pack()
  89.  
  90.  
  91.             def refresher():
  92.  
  93.                 global text
  94.                 r = requests.get('https://api.coindesk.com/v1/bpi/currentprice.json')
  95.                 json_dump = json.dumps(r.json())
  96.                 data = json.loads(json_dump)
  97.                 text.configure(text=data['time']['updated'] + " : $" + data['bpi']['USD']['rate'])
  98.                 root.after(60000, refresher)
  99.  
  100.  
  101.             draw()
  102.             refresher()
  103.  
  104.             #----Notebook----#
  105.  
  106.  
  107.             nb = ttk.Notebook(width=800, height=400)
  108.  
  109.             nb.pressed_index = None
  110.  
  111.  
  112.             #----Pestaña Portfolio----#
  113.  
  114.  
  115.             Portfolio = tkinter.Frame(nb, background="grey50")
  116.             nb.add(Portfolio, text='Portfolio', padding=5)
  117.    
  118.  
  119.             #----Combobox Shitcoins----#
  120.  
  121.  
  122.             combo = ttk.Combobox(Portfolio)
  123.             combo.grid(column=1, row=1, padx=5, pady=2)
  124.             labelShitcoins = Label(Portfolio, text="Shitcoin", font=("Lucida Console", 9, "bold"), bg="gray50")
  125.             labelShitcoins.grid(column=0, row=1, padx=5, pady=2)
  126.            
  127.             #----Entry Cantidad Monedas----#
  128.  
  129.  
  130.  
  131.             ent1portfolio = tkinter.Entry(Portfolio)
  132.             ent1portfolio.grid(column=1, row=2, padx=5, pady=2)
  133.             ent1portfolio.config(justify="center")
  134.             nombreLabel1 = Label(Portfolio, text="Cantidad", font=("Lucida Console", 9, "bold"), bg="gray50")
  135.             nombreLabel1.grid(column=0, row=2, padx=5, pady=2)
  136.  
  137.  
  138.  
  139.             #----Entry Precio Pagado Por Moneda----#
  140.  
  141.  
  142.  
  143.             ent2portfolio = tkinter.Entry(Portfolio)
  144.             ent2portfolio.grid(column=1, row=3, padx=5, pady=2)
  145.             ent2portfolio.config(justify="center")
  146.             nombreLabel2 = Label(Portfolio, text="Precio BTC", font=("Lucida Console", 9, "bold"), bg="gray50")
  147.             nombreLabel2.grid(column=0, row=3, padx=5, pady=2)
  148.  
  149.  
  150.             #----Entry Fecha Portfolio-----#
  151.  
  152.  
  153.  
  154.             nombreLabel3 = Label(Portfolio, text="Fecha de compra", font=("Lucida Console", 9, "bold"), bg="gray50")
  155.             nombreLabel3.grid(column=0, row=4, padx=5, pady=2)
  156.  
  157.  
  158.             #---- Boton Save ----#
  159.  
  160.             botonSave = Button(Portfolio, text="Save")
  161.             botonSave.place(x=238,y=105)
  162.  
  163.  
  164.  
  165.             #----Lista Datos Portfolio----#
  166.  
  167.             file = open('Bags.txt', 'wb')
  168.  
  169.             file.close()
  170.  
  171.  
  172.  
  173.  
  174.             #----Pestaña Charts----#
  175.  
  176.  
  177.             Charts = tkinter.Frame(nb, background="gray50")
  178.             nb.add(Charts, text='Charts', padding=5)
  179.  
  180.  
  181.             #----Market Stats----#
  182.  
  183.  
  184.             f3 = tkinter.Frame(nb, background="gray50")
  185.  
  186.  
  187.             #----News----#
  188.  
  189.  
  190.             f4 = tkinter.Frame(nb, background="gray50")
  191.  
  192.  
  193.             #----Others----#
  194.  
  195.             f5 = tkinter.Frame(nb, background="gray50")
  196.  
  197.  
  198.  
  199.             nb.add(f3, text='Market Stats', padding=0)
  200.             nb.add(f4, text='News', padding=0)
  201.             nb.add(f5, text='Others', padding=0)
  202.             nb.pack(expand=0, fill='both')
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.            
  211.  
  212.         else:
  213.             messagebox.showerror('Oops!','Username Not Found.')
  214.        
  215.  
  216.  
  217.  
  218.     def new_user(self):
  219.  
  220.         #Establish Connection
  221.  
  222.         with sqlite3.connect('quit.db') as db:
  223.             c = db.cursor()
  224.  
  225.         #Find Existing username if any take proper action
  226.  
  227.         find_user = ('SELECT * FROM user WHERE username = ?')
  228.         c.execute(find_user,[(self.username.get())])        
  229.         if c.fetchall():
  230.             messagebox.showerror('Error!','Username Taken Try a Diffrent One.')
  231.         else:
  232.             messagebox.showinfo('Success!','Account Created!')
  233.             self.log()
  234.  
  235.         #Create New Account
  236.  
  237.         insert = 'INSERT INTO user(username,password) VALUES(?,?)'
  238.         c.execute(insert,[(self.n_username.get()),(self.n_password.get())])
  239.         db.commit()
  240.  
  241.     #Frame Packing Methods
  242.  
  243.     def log(self):
  244.         self.username.set('')
  245.         self.password.set('')
  246.         self.crf.pack_forget()
  247.         self.head['text'] = 'LOGIN'
  248.         self.logf.pack()
  249.  
  250.     def cr(self):
  251.         self.n_username.set('')
  252.         self.n_password.set('')
  253.         self.logf.pack_forget()
  254.         self.head['text'] = 'Create Account'
  255.         self.crf.pack()
  256.  
  257.  
  258.  
  259.         ################################################
  260.  
  261.     def widgets(self):
  262.        
  263.         self.head = Label(self.master,text = 'LOGIN',font = ('Lucida Console',20),pady = 8)
  264.         self.head.pack()
  265.  
  266.  
  267.         self.logf = Frame(self.master,padx =10,pady = 14)
  268.         Label(self.logf,text = 'Username: ',font = ('Lucida Console',14),pady=6,padx=5).grid(sticky = W)
  269.         Entry(self.logf,textvariable = self.username,bd = 5,font = ('Lucida Console',14)).grid(row=0,column=1)
  270.         Label(self.logf,text = 'Password: ',font = ('Lucida Console',14),pady=6,padx=5).grid(sticky = W)
  271.         Entry(self.logf,textvariable = self.password,bd = 5,font = ('Lucida Console',14),show = '*').grid(row=1,column=1)
  272.  
  273.         #Boton Login
  274.  
  275.         Button(self.logf,text = ' Login ',bd = 3 ,font = ('Lucida Console',14),padx=5,pady=8,command=self.login).grid()
  276.  
  277.         #Boton Create Account
  278.  
  279.         Button(self.logf,text = ' Create Account ',bd = 3 ,font = ('Lucida Console',14),padx=5,pady=8,command=self.cr).grid(row=2,column=1)
  280.         self.logf.pack()
  281.        
  282.        
  283.  
  284.         self.crf = Frame(self.master,padx =10,pady = 10)
  285.         Label(self.crf,text = 'Username: ',font = ('Lucida Console',14),pady=5,padx=5).grid(sticky = W)
  286.         Entry(self.crf,textvariable = self.n_username,bd = 5,font = ('Lucida Console',14)).grid(row=0,column=1)
  287.         Label(self.crf,text = 'Password: ',font = ('Lucida Console',14),pady=5,padx=5).grid(sticky = W)
  288.         Entry(self.crf,textvariable = self.n_password,bd = 5,font = ('Lucida Console',14),show = '*').grid(row=1,column=1)
  289.         Button(self.crf,text = 'Create Account',bd = 3 ,font = ('Lucida Console',14),padx=5,pady=5,command=self.new_user).grid()
  290.         Button(self.crf,text = 'Go to Login',bd = 3 ,font = ('Lucida Console',14),padx=5,pady=5,command=self.log).grid(row=2,column=1)
  291.  
  292.  
  293.    
  294.    
  295.  
  296. root=Tk()
  297. login(root)
  298. style = ttk.Style(root)
  299. style.theme_use('clam')
  300.  
  301.  
  302. #Toolbar Menu#
  303.  
  304. def infoAbout():
  305.     messagebox.showinfo("VaporBot", "Built on 2019 by Mr. Wagecuck")
  306.  
  307. def warningLicense():
  308.     messagebox.showwarning("VaporBot License", "Free-License, Non registered")
  309.  
  310. def exitBot():
  311.     value=messagebox.askquestion("Exit", "Do you want to exit this program?")
  312.  
  313.     if value=="yes":
  314.         root.destroy()
  315.  
  316.  
  317. menuBar=Menu(root)
  318. root.config(menu=menuBar)
  319.  
  320. fileFile=Menu(menuBar, tearoff=0)
  321. fileFile.add_separator()
  322. fileFile.add_command(label="Quit", command=exitBot)
  323.  
  324. fileEdit=Menu(menuBar, tearoff=0)
  325.  
  326.  
  327.  
  328. fileTools=Menu(menuBar, tearoff=0)
  329.  
  330.  
  331.  
  332. fileHelp=Menu(menuBar, tearoff=0)
  333. fileHelp.add_command(label="License", command=warningLicense)
  334. fileHelp.add_separator()
  335. fileHelp.add_command(label="About", command=infoAbout)
  336.  
  337.  
  338. menuBar.add_cascade(label="File", menu=fileFile)
  339. menuBar.add_cascade(label="Edit", menu=fileEdit)
  340. menuBar.add_cascade(label="Tools", menu=fileTools)
  341. menuBar.add_cascade(label="Help", menu=fileHelp)
  342.  
  343.  
  344.  
  345. root.title("VaporBot")
  346. miFrame=Frame(root, "")
  347. miFrame.pack()
  348.  
  349.  
  350.  
  351. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement