生成了一個python計算器界面

又增加了幾個控件的支持。界面的代碼現在需要手工寫入。不用安裝GUI模塊。

程序稍微完善一下就發佈。

生成的界面是這樣:

源代碼:

'''
Created by freepy.
2020/5/28 9:21:23
'''

panel1 = '###[name:panel1,type:panel,align:alleft,width:320,]###'

memo1 = '###[name:memo1,type:memo,parent:panel1,align:altop,height:100,scrollbars:ssAutoBoth,]###'

panela  = '###[name:panela,type:panel,parent:panel1,align:altop,height:180,]###'

button1 = '###[name:button1,type:button,click:n1(),parent:panela,caption:1,left:10,top:10,width:60,height:30,align:alcustom,]###'
button2 = '###[name:button2,type:button,click:n2(),parent:panela,caption:2,left:70,top:10,width:60,height:30,align:alcustom,]###'
button3 = '###[name:button3,type:button,click:n3(),parent:panela,caption:3,left:130,top:10,width:60,height:30,align:alcustom,]###'
button4 = '###[name:button4,type:button,click:n4(),parent:panela,caption:4,left:190,top:10,width:60,height:30,align:alcustom,]###'
button5 = '###[name:button5,type:button,click:n5(),parent:panela,caption:5,left:250,top:10,width:60,height:30,align:alcustom,]###'

button6 = '###[name:button6,type:button,click:n6(),parent:panela,caption:6,left:10,top:40,width:60,height:30,align:alcustom,]###'
button7 = '###[name:button7,type:button,click:n7(),parent:panela,caption:7,left:70,top:40,width:60,height:30,align:alcustom,]###'
button8 = '###[name:button8,type:button,click:n8(),parent:panela,caption:8,left:130,top:40,width:60,height:30,align:alcustom,]###'
button9 = '###[name:button9,type:button,click:n9(),parent:panela,caption:9,left:190,top:40,width:60,height:30,align:alcustom,]###'
button0 = '###[name:button0,type:button,click:n0(),parent:panela,caption:0,left:250,top:40,width:60,height:30,align:alcustom,]###'

button_add = '###[name:button_add,type:button,click:func_add(),parent:panela,caption:加,left:10,top:80,width:60,height:30,align:alcustom,]###'
button_sub = '###[name:button_sub,type:button,click:func_sub(),parent:panela,caption:減,left:70,top:80,width:60,height:30,align:alcustom,]###'
button_mul = '###[name:button_mul,type:button,click:func_mul(),parent:panela,caption:乘,left:130,top:80,width:60,height:30,align:alcustom,]###'
button_div = '###[name:button_div,type:button,click:func_div(),parent:panela,caption:除,left:190,top:80,width:60,height:30,align:alcustom,]###'
button_do = '###[name:button_do,type:button,click:func_do(),parent:panela,caption:等於,left:250,top:80,width:60,height:30,align:alcustom,]###'

button_sin = '###[name:button_sin,type:button,click:func_sin(),parent:panela,caption:sin,left:10,top:120,width:60,height:30,align:alcustom,]###'
button_cos = '###[name:button_cos,type:button,click:func_cos(),parent:panela,caption:cos,left:70,top:120,width:60,height:30,align:alcustom,]###'
button_zkh = '###[name:button_zkh,type:button,click:func_skh(),parent:panela,caption:(,left:130,top:120,width:60,height:30,align:alcustom,]###'
button_ykh = '###[name:button_ykh,type:button,click:func_ykh(),parent:panela,caption:),left:190,top:120,width:60,height:30,align:alcustom,]###'

str_operat = ''

def n1():
    global str_operat
    str_operat = str_operat + '1'
    print("###memo1###", str_operat);

def n2():
    global str_operat
    str_operat = str_operat + '2'
    print("###memo1###", str_operat);

def n3():
    global str_operat
    str_operat = str_operat + '3'
    print("###memo1###", str_operat);

def n4():
    global str_operat
    str_operat = str_operat + '4'
    print("###memo1###", str_operat);

def n5():
    global str_operat
    str_operat = str_operat + '5'
    print("###memo1###", str_operat);

def n6():
    global str_operat
    str_operat = str_operat + '6'
    print("###memo1###", str_operat);

def n7():
    global str_operat
    str_operat = str_operat + '7'
    print("###memo1###", str_operat);

def n8():
    global str_operat
    str_operat = str_operat + '8'
    print("###memo1###", str_operat);

def n9():
    global str_operat
    str_operat = str_operat + '9'
    print("###memo1###", str_operat);

def n0():
    global str_operat
    str_operat = str_operat + '0'
    print("###memo1###", str_operat);

def func_add():
    global str_operat
    str_operat = str_operat + '+'
    print("###memo1###", str_operat);

def func_sub():
    global str_operat
    str_operat = str_operat + '-'
    print("###memo1###", str_operat);

def func_mul():
    global str_operat
    str_operat = str_operat + '*'
    print("###memo1###", str_operat);

def func_div():
    global str_operat
    str_operat = str_operat + '/'
    print("###memo1###", str_operat);


import math

def func_sin():
    global str_operat
    str_operat = str_operat + 'math.sin'
    print("###memo1###", str_operat);

def func_cos():
    global str_operat
    str_operat = str_operat + 'math.cos'
    print("###memo1###", str_operat);

def func_skh():
    global str_operat
    str_operat = str_operat + '('
    print("###memo1###", str_operat);

def func_ykh():
    global str_operat
    str_operat = str_operat + ')'
    print("###memo1###", str_operat);

def func_do():
    global str_operat
#    str_operat = str_operat.join('=')
    str_operat1 = str_operat + '='
    print("###memo1###", str_operat1, eval(str_operat));
    str_operat = ''

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章