FrontPage

#
# https://teratail.com/questions/82542
#

from tkinter import *
import sys


# spinboxの値が更新された時に呼ばれる関数
# Spinbox生成時にこの関数をcommand引数で渡しています。
# idxには更新されたSpinboxのIndex値が入ります
def update_value(idx):
    print("Update spinbox {}".format(idx))
    num_of_purchase = [int(s.get()) for s in spinboxes]
    sub_total = [n*p for n,p in zip(num_of_purchase, price)]
    total = sum(sub_total)

    # 表示するデータを作成する(適当に書きました)
    txt = ["{:5d} x {:2d} = {:5d}".format(p,n,t) for p,n,t in zip(price,num_of_purchase,sub_total)]
    txt.append("-----------------------------")
    txt.append("TOTAL : {}".format(total))

    # noteを更新する
    note.config(text='\n'.join(txt))



# Base window
window = Tk()

wc = Canvas(window, width = 2000, height = 2000)
wc.create_rectangle(0,0,2000,2000, fill = "paleturquoise")
wc.place(x = 0, y = 0)

# Setting the title
window.title("文房具の請求")

# Coloring canvas
for x in range(10):
    c = Canvas(window, width = 240, height = 150)
    c.create_rectangle(0,0,240,150, fill = "aliceblue")
    c.place(x = 30 + int(x/5) * 270, y = 30 + (x%5) * 155)

# Set Lavels
item = ["ノート","鉛筆","シャープペン","消しゴム","色鉛筆","ボールペン","油性ペン","蛍光ペン","はさみ","のり"]
for x in range(10):
    i = Label(text = item[x], bg = "#82EBF7")
    ko = Label(text = "個", bg = "aliceblue")
    i.place(x = 30 + int(x/5) * 270, y = 30 + (x%5) * 155)
    ko.place(x = 115 + int(x/5) * 270, y = 150 + (x%5) * 155)

# Set Spinboxes
spinboxes = []
for x in range(10):
    value = StringVar()
    s = Spinbox(window, from_=0, to=100, width = 10, textvariable=value, command=lambda idx=x:update_value(idx))
    s.place(x = 40 + int(x/5) * 270, y = 150 + (x%5) * 155)
    spinboxes.append(s)

# Set price
price = [100,20,150,50,40,120,180,200,350,240]
for x in range(10):
    t = Label(text = "{} 円".format(price[x]), bg = "aliceblue")
    t.place(x = 30 + int(x/5) * 270, y = 70 + (x%5) * 155)

# Set name
name = ["商品名1","商品名2","商品名3","商品名4","商品名5","商品名6","商品名7","商品名8","商品名9","商品名10"]
for x in range(10):
    n = Label(text = name[x], bg = "aliceblue")
    n.place(x = 30 + int(x/5) * 270, y = 50 + (x%5) * 155)

# Set window
window.geometry("1000x825+100+20")

# Set subwindow
sb = Canvas(window, width = 400, height = 700)
sb.create_rectangle(0,0,400,700, fill = "white")
sb.place(x = 570, y = 50)

text = Label(window, text="カート", bg = "#69D7E3" )
text.place(x=570, y=50)

note = Label(window, text = "", bg = "white" )
note.place(x=590, y=80)

window.mainloop()

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2019-08-19 (月) 17:36:54 (1095d)