Advertisement
dzu181

doitien v 2.1

May 22nd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1.  
  2. from tkinter import *
  3.  
  4. soft = Tk()
  5. soft.title("Doi tien v2.0")
  6. # exe
  7. def main():
  8.     # get data
  9.     mo1 = tien1.get()
  10.     mo2 = tien2.get()
  11.     soGia = text1.get()
  12.  
  13.     f = open('list.txt')
  14.     data = dict()
  15.     for line in f:
  16.         c = line.split(',')
  17.     for thing in c:
  18.         lis = thing.split(':')
  19.         data[lis[0]] = lis[1]
  20.     print(data)
  21.     # exchange
  22.     giatri = float(soGia) * float(data[mo1])/float(data[mo2])
  23.     giatri = round(giatri,2)
  24.     out.delete(0.0, END)
  25.     out.insert(END, giatri)
  26.  
  27. # Add a grid
  28. mainframe = Frame(soft)
  29. mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
  30. mainframe.columnconfigure(0, weight=1)
  31. mainframe.rowconfigure(0, weight=1)
  32.  
  33. # Create a Tkinter variable
  34. tien1 = StringVar(soft)
  35. tien2 = StringVar(soft)
  36. # Dictionary with options
  37. listTien1 = {'Dollar_US', 'Pound', 'SG_dollar', 'Baht', 'Yen', 'Yuan', 'VND', 'Won', 'Euro', 'Rub'}
  38. tien1.set('Dollar_US')
  39. listTien2 = {'Dollar_US', 'Pound', 'SG_dollar', 'Baht', 'Yen', 'Yuan', 'VND', 'Won', 'Euro', 'Rub'}
  40. tien2.set('Dollar_US')
  41.  
  42. popupMenu = OptionMenu(mainframe, tien1, *listTien1)
  43. Label(mainframe, text="Choose currency 1:").grid(row=1, column=1)
  44. text1 = Entry(soft, width = 30, bg ="white")
  45. text1.grid(row=2,column=0, sticky = N)
  46. popupMenu.grid(row=4, column=1)
  47.  
  48. out = Text(soft, width = 10, height = 2, background="white")
  49. out.grid(row=12, column=0, sticky=N)
  50.  
  51. popupMenu2 = OptionMenu(mainframe, tien2, *listTien2)
  52. Label(mainframe, text="Choose currency 2:").grid(row=5, column=1)
  53. # text2 = Entry(soft, width = 30, bg ="white")
  54. # text2.grid(row=6,column=0, sticky = N)
  55. popupMenu2.grid(row=7, column=1)
  56. Label(mainframe, text="Nhap so don vi:").grid(row=10, column=1)
  57.  
  58. Button(soft, text = "Exchange!", width =10, command = main).grid(row = 9, column = 0, sticky = N)
  59. soft.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement