当我按下其他班级的按钮时,如何运行其他班级的功能

时间:2019-05-05 15:01:33

标签: python-3.x tkinter

我正在制作一个程序,可以使我的母亲更轻松地进行会计核算。 所以我仍然有这个问题要运行将数据插入到树视图的功能。和其他课程中的按钮。

在这里对我是新手:D

我已经尝试在本地类中使用树视图调用该类的make函数,但是它仍然给我错误 init ()缺少1个必需的位置参数:'master'

这是我的具有树视图和功能的类,它将数据插入树视图:

class windowHitung():
    def __init__(self, master):
        self.master=master
        self.data = dataHolder()

        self.w1=tk.Toplevel(self.master)
        self.w1.wm_title("Program Hitung Untung dari modal")

        self.frameMenuHitung=Frame(self.w1, width=100, height=50)
        self.frameMenuHitung.grid(row=0, column=0)

        self.treeItems = ttk.Treeview(self.frameMenuHitung, columns=("nama", "jumlah", "harga"))
        self.treeItems['show'] = 'headings'
        self.treeItems.column('nama', anchor=N)
        self.treeItems.column('jumlah', anchor=N)
        self.treeItems.column('harga', anchor=N)
        self.treeItems.heading('nama', text="Nama Barang")
        self.treeItems.heading('jumlah', text="Jumlah")
        self.treeItems.heading('harga', text="Harga")
        self.treeItems.grid(row=0, column=0)

        self.itemscroll = ttk.Scrollbar(self.frameMenuHitung, command=self.treeItems.yview)
        self.itemscroll.grid(row=0, column=1, sticky='nsw')
        self.treeItems.config(yscrollcommand=self.itemscroll.set)


        self.labelModal = Label(self.frameMenuHitung, text="Modal ")
        self.labelModal.grid(row=1, column=0, sticky='w', padx=5)
        self.entryModal = Entry(self.frameMenuHitung)
        self.entryModal.grid(row=1, column=0, sticky='n')

        self.buttonTambah = ttk.Button(self.frameMenuHitung, text="Tambah", command=self.barangInputShow)
        self.buttonTambah.grid(row=2, column=0, padx=5, pady=5, sticky='w')
        self.buttonEdit = ttk.Button(self.frameMenuHitung, text="Edit")
        self.buttonEdit.grid(row=2, column=0, padx=5, pady=5, sticky='n')
        self.buttonBuang = ttk.Button(self.frameMenuHitung, text="Buang")
        self.buttonBuang.grid(row=2, column=0, padx=5, pady=5, sticky='e')

    def insertValue(self):
        self.treeItems.insert("", END, values=(dataHolder.namaBarang,"",""))

    def barangInputShow(self):
        inputBarang(self.master)

,这是树视图的输入数据的顶层。

class inputBarang(windowHitung):
    def __init__(self, master):
        self.master = master

        self.windowHitung = windowHitung()

        self.inputBarang = Toplevel(self.master)
        self.inputBarang.title("Input Item Properties")

        self.frameInput = Frame(self.inputBarang)
        self.frameInput.grid(row=0, column=0)

        self.labelBarang = Label(self.frameInput, text="Nama Barang")
        self.labelBarang.grid(row=0, column=0, sticky='w', padx=5, pady=6)
        self.entryBarang = Entry(self.frameInput)
        self.entryBarang.grid(row=0, column=1, sticky='w', padx=3, pady=6)

        self.labelJumlah = Label(self.frameInput, text="Jumlah Barang")
        self.labelJumlah.grid(row=1, column=0, sticky='w', padx=5, pady=6)
        self.entryJumlah = Entry(self.frameInput)
        self.entryJumlah.grid(row=1, column=1, sticky='w', padx=3, pady=6)

        self.labelHarga = Label(self.frameInput, text="Harga")
        self.labelHarga.grid(row=2, column=0, sticky='w', padx=5, pady=6)
        self.entryHarga = Entry(self.frameInput)
        self.entryHarga.grid(row=2, column=1, sticky='w', padx=3, pady=6)

        self.buttonInsertBarang = Button(self.frameInput, text="Tambah barang", width=20, height=5, command=self.windowHitung.insertValue)
        self.buttonInsertBarang.grid(row=3, columnspan=2, sticky="n")

如果您需要完整的代码。 :

from tkinter import *
from tkinter import ttk, messagebox
import tkinter as tk
from Hitung import *
import Hitung as cnt


class mainWindow():
    def keluar():
        pesanKeluar = messagebox.askyesno("Alert", "Apakah anda ingin keluar?")
        if pesanKeluar == True:
            root.destroy()
        else:
            pass

    def __init__(self, master):
        self.master=master
        self.frameMainMenu=Frame(master, width=100, height=50)
        self.frameMainMenu.pack()

        self.buttonHitung=Button(self.frameMainMenu, text="Hitung", command=self.windowHitungShow)
        self.buttonHitung.grid(row=0, padx=5, pady=2)

        self.buttonLihatRiwayat=Button(self.frameMainMenu, text="Riwayat")
        self.buttonLihatRiwayat.grid(row=1, padx=5, pady=2)

        self.buttonKeluar=Button(self.frameMainMenu, text="Keluar", command=mainWindow.keluar)
        self.buttonKeluar.grid(row=2, padx=5, pady=2)

    def windowHitungShow(self):
       windowHitung(self.master)

class dataHolder():
    namaBarang="test"
    jumlahBarang=0
    hargaBarang=00
    def __init__(self):
        dataHolder.namaBarang="test"
        dataHolder.jumlahBarang=0
        dataHolder.hargaBarang=0

class windowHitung():
    def __init__(self, master):
        self.master=master
        self.data = dataHolder()

        self.w1=tk.Toplevel(self.master)
        self.w1.wm_title("Program Hitung Untung dari modal")

        self.frameMenuHitung=Frame(self.w1, width=100, height=50)
        self.frameMenuHitung.grid(row=0, column=0)

        self.treeItems = ttk.Treeview(self.frameMenuHitung, columns=("nama", "jumlah", "harga"))
        self.treeItems['show'] = 'headings'
        self.treeItems.column('nama', anchor=N)
        self.treeItems.column('jumlah', anchor=N)
        self.treeItems.column('harga', anchor=N)
        self.treeItems.heading('nama', text="Nama Barang")
        self.treeItems.heading('jumlah', text="Jumlah")
        self.treeItems.heading('harga', text="Harga")
        self.treeItems.grid(row=0, column=0)

        self.itemscroll = ttk.Scrollbar(self.frameMenuHitung, command=self.treeItems.yview)
        self.itemscroll.grid(row=0, column=1, sticky='nsw')
        self.treeItems.config(yscrollcommand=self.itemscroll.set)


        self.labelModal = Label(self.frameMenuHitung, text="Modal ")
        self.labelModal.grid(row=1, column=0, sticky='w', padx=5)
        self.entryModal = Entry(self.frameMenuHitung)
        self.entryModal.grid(row=1, column=0, sticky='n')

        self.buttonTambah = ttk.Button(self.frameMenuHitung, text="Tambah", command=self.barangInputShow)
        self.buttonTambah.grid(row=2, column=0, padx=5, pady=5, sticky='w')
        self.buttonEdit = ttk.Button(self.frameMenuHitung, text="Edit")
        self.buttonEdit.grid(row=2, column=0, padx=5, pady=5, sticky='n')
        self.buttonBuang = ttk.Button(self.frameMenuHitung, text="Buang")
        self.buttonBuang.grid(row=2, column=0, padx=5, pady=5, sticky='e')

    def insertValue(self):
        self.treeItems.insert("", END, values=(dataHolder.namaBarang,"",""))

    def barangInputShow(self):
        inputBarang(self.master)


class inputBarang(windowHitung):
    def __init__(self, master):
        self.master = master

        self.windowHitung = windowHitung()

        self.inputBarang = Toplevel(self.master)
        self.inputBarang.title("Input Item Properties")

        self.frameInput = Frame(self.inputBarang)
        self.frameInput.grid(row=0, column=0)

        self.labelBarang = Label(self.frameInput, text="Nama Barang")
        self.labelBarang.grid(row=0, column=0, sticky='w', padx=5, pady=6)
        self.entryBarang = Entry(self.frameInput)
        self.entryBarang.grid(row=0, column=1, sticky='w', padx=3, pady=6)

        self.labelJumlah = Label(self.frameInput, text="Jumlah Barang")
        self.labelJumlah.grid(row=1, column=0, sticky='w', padx=5, pady=6)
        self.entryJumlah = Entry(self.frameInput)
        self.entryJumlah.grid(row=1, column=1, sticky='w', padx=3, pady=6)

        self.labelHarga = Label(self.frameInput, text="Harga")
        self.labelHarga.grid(row=2, column=0, sticky='w', padx=5, pady=6)
        self.entryHarga = Entry(self.frameInput)
        self.entryHarga.grid(row=2, column=1, sticky='w', padx=3, pady=6)

        self.buttonInsertBarang = Button(self.frameInput, text="Tambah barang", width=20, height=5, command=self.windowHitung.insertValue)
        self.buttonInsertBarang.grid(row=3, columnspan=2, sticky="n")




if __name__=="__main__":
    root=Tk()
    root.wm_title("Program Hitung Untung dari modal")
    #root.geometry("200x200")
    main = mainWindow(root)
    root.mainloop()

感谢看到我的请求

我希望按钮能够运行功能,但仍然会给我带来错误

0 个答案:

没有答案