栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python -tkinter 汇率转换程序

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python -tkinter 汇率转换程序

testgui.py 

from ccapp import CCApp
from gui import GUIInterface

inter=GUIInterface()
cc=CCApp(inter)
cc.run()

gui.py

# -*- codeing: utf-8 -*-
from tkinter import *
class GUIInterface:
    def __init__(self):
        self.root=Tk()
        self.root.title("Currency Converter")
        
        self.qFlag=False
        self.fc=StringVar()
        self.fc.set('USD')
        self.to='RMB'
        self.amt=0
        self.aRMB=StringVar()
        self.aRMB.set('0.00')
        self.aFC=StringVar()
        self.aFC.set('0.00')

        Label(self.root,textvariable=self.fc).grid(row=0,column=0,sticky=W) #sticky
        Label(self.root,text='RMB').grid(row=0,column=2,sticky=W)
        self.e1=Entry(self.root,textvariable=self.aFC)
        self.e1.grid(row=1,column=0,rowspan=2)
        self.e2=Entry(self.root,textvariable=self.aRMB)
        self.e2.grid(row=1,column=2,rowspan=2)
        self.b1=Button(self.root,text='----->',command=self.toRMB)
        self.b1.grid(row=1,column=1)
        self.b2=Button(self.root,text='<-----',command=self.toFC)
        self.b2.grid(row=2,column=1)
        
        self.f=Frame(self.root)
        self.f.grid(row=3,column=0,columnspan=3)
        self.r1=Radiobutton(self.f,text='USD',variable=self.fc,value='USD')
        self.r1.grid(row=0,column=0)
        self.r2=Radiobutton(self.f,text='Euro',variable=self.fc,value='Euro')
        self.r2.grid(row=0,column=1)        
        self.r3=Radiobutton(self.f,text='Yen',variable=self.fc,value='Yen')
        self.r3.grid(row=0,column=2)       
        self.r4=Radiobutton(self.f,text='Pound',variable=self.fc,value='Pound')
        self.r4.grid(row=0,column=3)
        
        self.rate=Button(self.root,text='Update Rates')
        self.rate.grid(row=4,column=1)
        self.qb=Button(self.root,text='Quit',command=self.close)
        self.qb.grid(row=5,column=1)
    
    def getInfo(self):
        self.root.mainloop()
        return self.qFlag,self.fc.get(),self.to,self.amt
    
    def showInfo(self,r):
        rStr="%.2f" % r
        if self.to=='RMB':
            self.aRMB.set(rStr)
        else:
            self.aFC.set(rStr)
    
    def toRMB(self):
        self.to='RMB'
        self.amt=eval(self.aFC.get())
        self.root.quit()
    
    def toFC(self):
        self.to=self.fc.get()
        self.amt=eval(self.aRMB.get())
        self.root.quit()       
        
    def close(self):
        self.qFlag=True
        self.root.quit() 
        self.root.destroy()    
        
            
        #p314
        

if __name__ == '__main__':
    pass

ccapp.py

# -*- coding: utf-8 -*-
#汇率模型
class CCApp:
    def __init__(self,inter): #代表用户界面inter
        self.xRate={'USD':6.306,'Euro':8.2735,'Yen':0.0775,'Pound':10.0486}
        self.interface = inter
    def run(self):
        while True:
            byeqFlag,fc,to,amount = self.interface.getInfo()
            if byeqFlag:  
                break
            elif to == 'RMB':
                result = amount * self.xRate[fc]
            else:
                result = amount / self.xRate[fc]
            self.interface.showInfo(result)  

        
def main():
    cp=CCApp()
    cp.run()

if __name__ == '__main__':
    main()
    pass

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/928852.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号