tkinter) 결과값이 각 행마다 나오게 하기

조회수 435회

제가 원하는 건 submit 클릭 시에 각 행마다 temperature 값이 나왔으면 좋겠는데... 마지막 실행한 줄만 값이 나옵니다 모든 행에 나오게 하는 방법이 있을까요!?!?!? 그리고 add row를 하면 모든 칸에 실수를 넣어야만 결과값이 나오는데 한줄만 넣고 나오게 할 수는 없을까요!

그리고 delete를 누르면 마지막 행만 지워지네요 ㅎㅎ 이것도 수정하고 싶은데... 어떻게 해야할지 막막합니다 힌트라도 부탁드려용!!!

from tkinter import *
from tkinter import ttk

class App(ttk.Frame):
    num_rows = 2
    entry_list = []

    def __init__(self, master, *args, **kwargs):
        ttk.Frame.__init__(self, master, *args, **kwargs)
        self.master = master
        self.label_frame = ttk.Frame(self.master)
        self.label_frame.grid()
        self.label_list = []

        label1 = Label(root, width=5, text="No.", font=("Bahnschrift, 9"), fg='black')
        label2 = Label(root, width=12, text="Chip", font=("Bahnschrift, 9"), fg='black')
        label3 = Label(root, width=12, text="Length[mm] : ", font=("Bahnschrift, 9"), fg='black')
        label4 = Label(root, width=12, text="Width[mm] : ", font=("Bahnschrift, 9"), fg='black')
        label9 = Label(root, width=12, text="Temp[C] : ", font=("Bahnschrift, 9"), fg='red')

        #grid
        label1.grid(row=0, column=0, padx=1, pady=10)
        label2.grid(row=0, column=1, padx=2, pady=10)
        label3.grid(row=0, column=2, padx=2, pady=10)
        label4.grid(row=0, column=3, padx=2, pady=10)
        label9.grid(row=0, column=8, padx=2, pady=10)


        ##유동
        self.Number_field = Entry(root, width=5)
        self.Length_field = Entry(root, width=9)
        self.Width_field = Entry(root, width=9)

        self.Temperature_field = Entry(root, width=9)

        self.Number_field.grid(row=1, column=0, padx=1, pady=1)
        self.Length_field.grid(row=1, column=2, padx=1, pady=1)
        self.Width_field.grid(row=1, column=3, padx=1, pady=1)

        self.Temperature_field.grid(row=1, column=8, padx=1, pady=1)

        strs = StringVar()
        strs2 = StringVar()
        combx1 = ttk.Combobox(root, width=9, textvariable=strs)

        combx1['values'] = (' Natural', ' Forced(Fan)')
        combx1.current()
        combx1.grid(column=7, row=1)

        combx2 = ttk.Combobox(root, width=9, textvariable=strs2)
        combx2['values'] = ('CPU', 'eMMC', 'PMIC')
        combx2.grid(column=1, row=1)
        combx2.current()

        # Create a Submit Button and attached

        button1 = Button(root, text="Submit", bg="black", fg="white", command=self.cal_Temp)
        button1.grid(row=100, column=0, pady=10)
        button2 = Button(root, text="Clear", fg="blue", command=self.clear_all)
        button2.grid(row=100, column=1, pady=10)
        button3 = Button(root, text="Add Row (+)",  command=self.add_new)
        button3.grid(row=102, column=0, pady=10)
        button4 = Button(root, text="Delete Row (-)", command=self.delete)
        button4.grid(row=102, column=1, pady=10)



    def clear_all(self):
        self.Number_field.delete(0,END)
        self.Length_field.delete(0, END)
        self.Width_field.delete(0, END)

        self.Temperature_field.delete(0, END)



        #이거 지워도 되는지
        self.Length_field.focus_set()

    def cal_Temp(self):
        Length = float(self.Length_field.get())
        Width = float(self.Width_field.get())
        h = 1

        Temperature = float(((((Length * Width * 2) + (Length * Width * 2) + (
                    Length * Width * 2)) / 1000000)) / h + 85)
        self.Temperature_field.insert(10,Temperature)


    def add_new(self):


        self.num_rows += 1


        self.Number_field = Entry(root, width=5)
        self.Length_field = Entry(root, width=9)
        self.Width_field = Entry(root, width=9)

        self.Temperature_field = Entry(root, width=9)

        self.Number_field.grid(row=self.num_rows, column=0, padx=1, pady=1)
        self.Length_field.grid(row=self.num_rows, column=2, padx=1, pady=1)
        self.Width_field.grid(row=self.num_rows, column=3, padx=1, pady=1)

        self.Temperature_field.grid(row=self.num_rows, column=8, padx=1, pady=1)



        strs = StringVar()
        strs2 = StringVar()
        self.combx1 = ttk.Combobox(root, width=9, textvariable=strs)

        self.combx1['values'] = (' Natural', ' Forced(Fan)')
        self.combx1.current()
        self.combx1.grid(row=self.num_rows, column=7)

        self.combx2 = ttk.Combobox(root, width=9, textvariable=strs2)
        self.combx2['values'] = ('CPU', 'eMMC', 'PMIC')
        self.combx2.grid(row=self.num_rows, column=1)
        self.combx2.current()
        self.ics=self.num_rows
        self.Number_field.insert(10, self.ics-1)


    def delete(self):
        self.num_rows -= 1
        self.Number_field.destroy()
        self.Length_field.destroy()
        self.Width_field.destroy()

        self.Temperature_field.destroy()
        self.combx1.destroy()
        self.combx2.destroy()


        self.ics -= 1




if __name__ == "__main__":
    root = Tk()
    root.configure(background='snow')
    root.geometry("1000x450")
    root.title("Expectation of Temp Calculator")
    my_app = App(root)
    root.mainloop()


  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)