本文介绍了在热敏打印机python上打印收据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 python 上创建一个库存系统.我需要在所有销售完成后生成打印收据.当我点击保存按钮时.我使用了 mysql 数据库.它有销售和销售产品表销售表由以下列组成 - id、小计、支付、余额.sales_products 表由以下列组成 –id,sales_id,item,qty,price,total 需要将数据保存到两个不同的表中,当我同时点击保存按钮时打印收据应该显示.我不知道如何保存多张表上的数据我不知道如何将所有树视图保存在数据库中.我在保存功能中得到了下面的 lastinsert id.

i am creating a inventory system on python.i need genterating print recipt after all sales done.when i click save button.i have using mysql database. it has sales and sales product tablesales tables consist of following colums – id,subtotal,pay,balance.sales_products tables consist of following colums –id,sales_id,item,qty,price,total need to save the data into two diffent tables when i hit save button at the same time print recipt should display.i don't know to how to save the data on multipule tables i don't know how to save all the treeview save on the database . i got lastinsert id below in the save function.

from tkinter import ttk
from tkinter import *
from tkinter import messagebox

import mysql.connector

def save():
    totall = float(tot.cget("text"))
    pay = float(e11.get())
    bal = pay - totall

    mysqldb = mysql.connector.connect(host="localhost", user="root", password="", database="milkshop")
    mycursor = mysqldb.cursor()

    try:
        sql = "INSERT INTO sales (id,subtotal,pay,balance) VALUES (%s, %s, %s, %s)"
        val = ("", totall, pay, bal)
        mycursor.execute(sql, val)
        mysqldb.commit()
        lastid = mycursor.lastrowid


    except Exception as e:

        print(e)
        mysqldb.rollback()
        mysqldb.close()

def pay():
    totall = float(tot.cget("text"))
    pay = float(e11.get())
    bal = pay - totall
    balText.set(bal)

root = Tk()
root.title("Inventory System using Python")
root.geometry("1000x600")
global e1
global e2
global e3
global e4
global totText
global balText

totText = StringVar()
balText = IntVar()

Label(root, text="Inventory System using Python", font="arial 22 bold").place(x=5, y=10)

var1 = IntVar()
Checkbutton(root, text="Thai Fried Rice", variable=var1).place(x=10, y=50)

var2 = IntVar()
Checkbutton(root, text="Basil Fried Rice", variable=var2).place(x=10, y=80)

var3 = IntVar()
Checkbutton(root, text="Pineapple Fried Rice", variable=var3).place(x=10, y=110)

var4 = IntVar()
Checkbutton(root, text="Crab Fried Rice", variable=var4).place(x=10, y=140)

var5 = IntVar()
Checkbutton(root, text=" Fish Fried Rice  ", variable=var5).place(x=10, y=170)
Label(root, text="Total").place(x=600, y=10)

Label(root, text="Pay").place(x=600, y=50)
Label(root, text="Balance").place(x=600, y=80)


e8 = Entry(root)
e8.place(x=300, y=110)

e9 = Entry(root)
e9.place(x=300, y=140)

e10 = Entry(root)
e10.place(x=300, y=170)

tot = Label(root, text="", font="arial 22 bold", textvariable=totText)
tot.place(x=650, y=10)

e11 = Entry(root)
e11.place(x=650, y=50)

e12 = Entry(root)

balance = Label(root, text="", font="arial 22 bold", textvariable=balText).place(x=650, y=80)
Button(root, text="Add", command=show, height=3, width=13).place(x=10, y=220)
Button(root, text="PayNow", command=pay, height=3, width=13).place(x=650, y=120)
Button(root, text="Save", command=save, height=3, width=13).place(x=750, y=120)



cols = ('item', 'price', 'qty', 'total')
listBox = ttk.Treeview(root, columns=cols, show='headings')

for col in cols:
    listBox.heading(col, text=col)
    listBox.grid(row=1, column=0, columnspan=2)
    listBox.place(x=10, y=300)

root.mainloop()

推荐答案

以下是我认为您应该如何处理回执.

Here is how i think you should proceed with the reciept.

from tkinter import *

root = Tk()

def reciept():
    top = Toplevel()
    price1 = 3000
    qty1 = 3
    total1 = price1*qty1

    price2 = 5000
    qty2 = 4
    total2 = price1*qty2

    l = Label(top,text='---------RECIEPT----------')
    l.pack()
    heading = Label(top,text='PRICE\tQTY\tTOTAL')
    heading.pack()

    item1 = Label(top,text=f'{price1}\t{qty1}\t{total1}')
    item1.pack()

    item2 = Label(top,text=f'{price2}\t{qty2}\t{total2}')
    item2.pack()

b = Button(root,text='Print reciept',command=reciept)
b.pack(padx=10,pady=10)
root.mainloop()

\t 将在字母末尾添加 4 个空格.

The \t will add 4 spaces to the end of the letter.

您可以用您的 e1.get() 和全部替换价格.

You can replace prices with your e1.get() and all.

您也可以在这里使用 grid() ,但它可能很麻烦并且需要更多的行.

You can also use grid() here but it might be cumbersome and takes more lines.

在此处查看如何使用 python 进行打印

希望你有想法.

干杯

这篇关于在热敏打印机python上打印收据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 19:02
查看更多