PYQT5 Kodlarını Python scripte implemente etmek

python
tkinter

#1

Arkadaşlar daha önce tkinter ile yazdığım scriptimi Pyqt ile yazmak istedim. İlk script pyqt5’e çevril QT designer kodları ikinci script ise tkinter ile yazmış olduğum ve çalışan kodlar 2. scriptte tkinter ile yazmış olduğum kodlar yerine pyqt5 kodlarını kullanıp scripti çalışır hale getirmek. database’ye yazdırmak database den bilgi çekmek toplamı otomatik hesaplatmak.
Biraz karışık bir yapı oldu. Eğer yardımcı olmak isteyen arkadaş olursa benimle bağlantıya geçerse detaylı açıklama yapabilirim. şimdiden yardımlarınız için teşekkür ederim.

# Form implementation generated from reading ui file 'deneme.ui'
#
# Created by: PyQt5 UI code generator 5.6
#
# WARNING! All changes made in this file will be lost!
# -*- coding: utf-8 -*-

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(20, 13, 151, 21))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
        self.textBrowser.setGeometry(QtCore.QRect(280, 10, 341, 31))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.textBrowser.setFont(font)
        self.textBrowser.setObjectName("textBrowser")
        self.textBrowser_2 = QtWidgets.QTextBrowser(self.centralwidget)
        self.textBrowser_2.setGeometry(QtCore.QRect(280, 87, 161, 31))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.textBrowser_2.setFont(font)
        self.textBrowser_2.setObjectName("textBrowser_2")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(20, 90, 111, 21))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(20, 133, 151, 21))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")
        self.dateEdit = QtWidgets.QDateEdit(self.centralwidget)
        self.dateEdit.setGeometry(QtCore.QRect(280, 130, 101, 22))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.dateEdit.setFont(font)
        self.dateEdit.setObjectName("dateEdit")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(20, 163, 121, 21))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.label_4.setFont(font)
        self.label_4.setObjectName("label_4")
        self.comboBox = QtWidgets.QComboBox(self.centralwidget)
        self.comboBox.setGeometry(QtCore.QRect(280, 160, 91, 22))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.comboBox.setFont(font)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.label_6 = QtWidgets.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(20, 190, 121, 21))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.label_6.setFont(font)
        self.label_6.setObjectName("label_6")
        self.textBrowser_4 = QtWidgets.QTextBrowser(self.centralwidget)
        self.textBrowser_4.setGeometry(QtCore.QRect(280, 190, 231, 31))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.textBrowser_4.setFont(font)
        self.textBrowser_4.setObjectName("textBrowser_4")
        self.textBrowser_5 = QtWidgets.QTextBrowser(self.centralwidget)
        self.textBrowser_5.setGeometry(QtCore.QRect(280, 240, 231, 31))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.textBrowser_5.setFont(font)
        self.textBrowser_5.setObjectName("textBrowser_5")
        self.label_7 = QtWidgets.QLabel(self.centralwidget)
        self.label_7.setGeometry(QtCore.QRect(20, 240, 91, 21))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.label_7.setFont(font)
        self.label_7.setObjectName("label_7")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(350, 370, 91, 23))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.pushButton.setFont(font)
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(350, 400, 91, 23))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.pushButton_2.setFont(font)
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_3.setGeometry(QtCore.QRect(350, 430, 91, 23))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.pushButton_3.setFont(font)
        self.pushButton_3.setObjectName("pushButton_3")
        self.label_8 = QtWidgets.QLabel(self.centralwidget)
        self.label_8.setGeometry(QtCore.QRect(20, 290, 141, 21))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.label_8.setFont(font)
        self.label_8.setObjectName("label_8")
        self.dateEdit_2 = QtWidgets.QDateEdit(self.centralwidget)
        self.dateEdit_2.setGeometry(QtCore.QRect(280, 290, 101, 22))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.dateEdit_2.setFont(font)
        self.dateEdit_2.setObjectName("dateEdit_2")
        self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_4.setGeometry(QtCore.QRect(310, 490, 191, 23))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.pushButton_4.setFont(font)
        self.pushButton_4.setObjectName("pushButton_4")
        self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_5.setGeometry(QtCore.QRect(310, 460, 191, 23))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.pushButton_5.setFont(font)
        self.pushButton_5.setObjectName("pushButton_5")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(20, 50, 151, 21))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.label_5.setFont(font)
        self.label_5.setObjectName("label_5")
        self.textBrowser_3 = QtWidgets.QTextBrowser(self.centralwidget)
        self.textBrowser_3.setGeometry(QtCore.QRect(280, 50, 161, 31))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.textBrowser_3.setFont(font)
        self.textBrowser_3.setObjectName("textBrowser_3")
        self.label_9 = QtWidgets.QLabel(self.centralwidget)
        self.label_9.setGeometry(QtCore.QRect(400, 290, 141, 21))
        font = QtGui.QFont()
        font.setFamily("Bookman Old Style")
        font.setPointSize(12)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.label_9.setFont(font)
        self.label_9.setObjectName("label_9")
        self.checkBox = QtWidgets.QCheckBox(self.centralwidget)
        self.checkBox.setGeometry(QtCore.QRect(480, 280, 91, 40))
        self.checkBox.setText("")
        self.checkBox.setObjectName("checkBox")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
        self.menubar.setObjectName("menubar")
        self.menuMUHASEBEC_M = QtWidgets.QMenu(self.menubar)
        self.menuMUHASEBEC_M.setObjectName("menuMUHASEBEC_M")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.menubar.addAction(self.menuMUHASEBEC_M.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label.setText(_translate("MainWindow", "FİRMA ADI"))
        self.label_2.setText(_translate("MainWindow", "FATURA NO"))
        self.label_3.setText(_translate("MainWindow", "FATURA TARİHİ"))
        self.label_4.setText(_translate("MainWindow", "KDV ORANI"))
        self.comboBox.setItemText(0, _translate("MainWindow", "1"))
        self.comboBox.setItemText(1, _translate("MainWindow", "8"))
        self.comboBox.setItemText(2, _translate("MainWindow", "18"))
        self.label_6.setText(_translate("MainWindow", "MATRAH"))
        self.label_7.setText(_translate("MainWindow", "TOPLAM"))
        self.pushButton.setText(_translate("MainWindow", "KAYDET"))
        self.pushButton_2.setText(_translate("MainWindow", "SORGULA"))
        self.pushButton_3.setText(_translate("MainWindow", "SİL"))
        self.label_8.setText(_translate("MainWindow", "ÖDEME TARİHİ"))
        self.pushButton_4.setText(_translate("MainWindow", "ÖDEME SORGULA"))
        self.pushButton_5.setText(_translate("MainWindow", "VERGİ NO SORGULA"))
        self.label_5.setText(_translate("MainWindow", "VERGİ NO"))
        self.label_9.setText(_translate("MainWindow", "ÖDENDİ"))
        self.menuMUHASEBEC_M.setTitle(_translate("MainWindow", "MUHASEBECİM"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

> Blok-alıntı
#!/usr/bin/env python
#-*-coding:utf8-*-
from tkinter import *
from tkinter.ttk import *
import sqlite3
from tkinter import StringVar
from tkinter.ttk import Entry

global ekle1
global ekle2
global ekle3
global ekle4
global ekle5
global ekle6
global ekle7

   
    
pencere=Tk()
pencere.title("MUHASEBE PROGRAMI BULENT V.1")
pencere.geometry('2000x10000')

Musteri_unvani=Label(pencere) # company name
etiket1=Label(text="Lütfen Müşteri Ünvanını Giriniz!")
etiket1.pack()
Musteri_unvani=Entry()
Musteri_unvani.pack()

Vergi_no=Label(pencere) # VAT Number
etiket8=Label(text="Lütfen Vergi Numarasını Giriniz!")
etiket8.pack()
Vergi_no=Entry()
Vergi_no.pack()


Fatura_no=Label(pencere) # Invoice number
etiket2=Label(text="Lütfen Fatura Numarasını Giriniz!")
etiket2.pack()
Fatura_no=Entry()
Fatura_no.pack()

Fatura_tarihi=Label(pencere) #Invoice date
etiket3=Label(text="Lütfen Fatura Tarihini Giriniz!")
etiket3.pack()
Fatura_tarihi=Entry()
Fatura_tarihi.pack()


category ={'ALIM':[1,8,18],'SATIM':[1,8,18],'ALIM İADE':[1,8,18],'SATIM İADE':[1,8,18],'TEVKİFAT KDV':[9/10]}
def getUpdate(event):
    box2['values'] = category[(box1.get())]

Fatura_turu=Label(pencere)  
etiket4=Label(text="Lütfen Fatura Türünü Seçiniz!")
etiket4.pack()
value = StringVar()
box1 = Combobox(pencere, textvariable=value, state='readonly')
box1['values'] = list(category.keys())
box1.bind('<<ComboboxSelected>>',getUpdate)
box1.current(0)
box1.pack()

Tutar=Label(pencere)
etiket5=Label(text="Lütfen Tutarı Giriniz!")
etiket5.pack()
Tutar =Entry()
Tutar.pack()

Kdv_orani=Label(pencere)
etiket6=Label(text="Lütfen KDV oranını Seçiniz!")
etiket6.pack()
box2 = Combobox(pencere)
box2.pack()


Toplam=Label(pencere)
etiket7=Label(text="Lütfen Fatura Toplamını Giriniz!")
etiket7.pack()
Toplam = Entry()
Toplam.pack()

def database():
    #calculate the value of toplam here
    Toplam.delete(0,'end') 
    toplam = 0
    tutar = float(Tutar.get())
    kdv_orani = float(box2.get())
    toplam = tutar+(tutar*(kdv_orani/100))
    Toplam.insert(0,str(toplam))
    
    baglanti = sqlite3.connect('accounting.db')
    if(baglanti):
        print('Baglanti Basarili!')
    else:
        print('Baglanti Basarisiz!')


    veritabani_sec = baglanti.cursor()

    ekle1=Musteri_unvani.get()
    ekle2=Fatura_no.get()
    ekle3=Fatura_tarihi.get()
    ekle4=box1.get()
    ekle5=float(Tutar.get())
    ekle6=float(box2.get())
    ekle7=float(Toplam.get())
    ekle8=Vergi_no.get()  

    #seçili veritabanına veri ekliyoruz.
    veritabani_sec.execute ("""INSERT INTO accountant VALUES ('"""+ str(ekle1) +"""','"""+ str(ekle2) +"""','"""+ str(ekle8) +"""','"""+ str(ekle3) +"""','"""+ str(ekle4) +"""','"""+ str(ekle5) +"""','"""+ str(ekle6) +"""','"""+ str(ekle7) +"""')""")
    baglanti.commit()
    baglanti.close()
    
def arama():
    baglanti = sqlite3.connect('accounting.db')
    if(baglanti):
        print('Baglanti Basarili!')
    else:
        print('Baglanti Basarisiz!')

    #baglanti kurulan veriyi seç. 
    veritabani_sec = baglanti.cursor()
    #seçili olan veritabanın verileri okuyalım
    oku = veritabani_sec.execute("SELECT * FROM accountant")
    print(oku.fetchone())
 
    baglanti.commit()
    baglanti.close()

 
dugme1=Button(pencere)
dugme1.config(text="Kaydınızı ekleyiniz.")
dugme1.config(command=database)
dugme1.pack()
dugme2=Button(pencere)
dugme2.config(text="Kayıt arayınız.")
dugme2.config(command=arama)
dugme2.pack()
dugme3=Button(pencere)
dugme3.config(text="Kayıt siliniz.")
dugme3.config(command=database)
dugme3.pack()