zoukankan      html  css  js  c++  java
  • 计算器

    import tkinter as tk
    from tkinter import ttk
    
    import pandas as pd
    from prettytable import PrettyTable
    
    '''号码投注方案计算器'''
    
    # 程序界面
    class AppWindow(tk.Frame):
        def __init__(self, master=None):
            super().__init__(master)
            self.grid(row=0, column=0, sticky="nsew")
            self.setupUI()
    
        def setupUI(self):
            leftwidth = 5
            rightwidth = 15
            
            
            mainframe = tk.Frame(self)
            mainframe.pack(fill="x")
            
            # 第一行:特码毛赔率
            rowframe1 = tk.Frame(mainframe)
            rowframe1.pack(fill="x", ipadx=3, ipady=3)
    
            self.peilv = tk.DoubleVar()
            self.peilv.set(42)
            tk.Entry(rowframe1, textvariable=self.peilv).pack(side=tk.RIGHT)
            
            tk.Label(rowframe1, text="赔率").pack(side=tk.RIGHT)
    
            
            # 第二行:起始倍数
            rowframe2 = tk.Frame(mainframe)
            rowframe2.pack(fill="x", ipadx=3, ipady=3)
            
            self.start_beishu = tk.IntVar()
            self.start_beishu.set(1)
            tk.Entry(rowframe2, textvariable=self.start_beishu).pack(side=tk.RIGHT)
            
            tk.Label(rowframe2, text="起始倍数").pack(side=tk.RIGHT)
            
            # 第三行:注数
            rowframe3 = tk.Frame(mainframe)
            rowframe3.pack(fill="x", ipadx=3, ipady=3)
            
            self.zhushu = tk.IntVar()
            self.zhushu.set(10)
            tk.Entry(rowframe3, textvariable=self.zhushu).pack(side=tk.RIGHT)
            
            tk.Label(rowframe3, text="注数").pack(side=tk.RIGHT)
            
            # 第四行:最小收益率
            rowframe4 = tk.Frame(mainframe)
            rowframe4.pack(fill="x", ipadx=3, ipady=3)
            
            self.min_shouyilv = tk.DoubleVar()
            self.min_shouyilv.set(0.5)
            tk.Entry(rowframe4, textvariable=self.min_shouyilv).pack(side=tk.RIGHT)
            
            tk.Label(rowframe4, text="最小收益率").pack(side=tk.RIGHT)
            
            
            # 第五行:按钮
            rowframe5 = tk.Frame(mainframe)
            rowframe5.pack(fill="x", ipadx=3, ipady=3)
            ttk.Button(rowframe5, text='确定', command=self.calc).pack(side=tk.RIGHT)
            
        def calc_a_row(self, index, last_beishu, last_cumsumtouru):
            '''根据上期倍数、上期累计投入,计算本期'''
            zhushu, peilv, min_shouyilv = self.zhushu.get(), self.peilv.get(), self.min_shouyilv.get()
            bs = last_beishu
            while True:
                cumsumtouru = last_cumsumtouru + bs * zhushu # 累计投入
                cumsumshouyi = bs * peilv - cumsumtouru # 累计收益
                if cumsumshouyi/cumsumtouru < min_shouyilv:
                    bs += 1
                else:
                    break
            # ['期数','倍数','注数','本期投入','累计投入','本期收益','累计收益','累计收益率']
            return [index+1, bs, zhushu, bs*zhushu, cumsumtouru, round(bs*peilv, 2), round(cumsumshouyi, 2), round(cumsumshouyi/cumsumtouru, 4)]
            
        def calc_n_row(self, n=10):
            '''计算n期'''
            res = []
            for i in range(n):
                if i == 0: 
                    res.append(self.calc_a_row(i, self.start_beishu.get(), 0))
                elif i > 0:
                    res.append(self.calc_a_row(i, res[-1][1], res[-1][4]))
            return res
        
        def calc(self):
            '''倍投计算(用prettytable显示结果)'''
            n = 10
            res = self.calc_n_row(n)
            
            table = PrettyTable(['期数','倍数','注数','本期投入','累计投入','本期收益','累计收益','累计收益率'])
            for i in range(n):
                table.add_row(res[i])
            print(table)
            
        def calc2(self):
            '''倍投计算(用pandas显示结果)'''
            n = 10
            res = self.calc_n_row(n)
            
            df = pd.DataFrame(res, columns=['期数','倍数','注数','本期投入','累计投入','本期收益','累计收益','累计收益率'])
            print(df)
        
    def main():
        root = tk.Tk()
        root.columnconfigure(0, weight=1)
        root.rowconfigure(0, weight=1) # Grid管理器允许通过几个方法来控制组件在容器中的位置。weight选项指出一个行或列的相对缩放比例,针对一个行,如果将weight设为3,那么他将以三倍于weight值为1的比例伸展。默认值是0,表明当用户改变窗口大小时,单元格的大小保持不变。
        #root.geometry('640x360')  # 主窗口大小
        root.resizable(width=False, height=False) # 禁止改变大小
        root.title("计算器")
    
        app = AppWindow(root)
        app.mainloop()
    
    
    if __name__ == "__main__":
        main()
        pass
    
  • 相关阅读:
    js 实现自增长
    常用的js脚本验证
    Jquery 收集
    Jquery 常用操作搜集
    Jquery 点击绑定行 弹出详细页面
    Jquery 了解
    Html 标尺
    Editor Guidelines
    程序员需要做到
    jS 回车事件
  • 原文地址:https://www.cnblogs.com/hhh5460/p/5686919.html
Copyright © 2011-2022 走看看