python class 변수 활용 질문입니다.

조회수 537회

python Tkinter 에서 프로그램을 작성하고 있습니다. Tkinter entry 에서 입력받은 값을 다른 클래스에서 상속받아서 활용하고 싶습니다. 도와주세요.

import tkinter

from tkinter import *

from tkinter import filedialog

class Day_Simple:

    st_day = ""
    en_day = ""
    city_num = ""
    def __init__(self):
        self.day_simple = Tk()
        self.day_simple.title("테스트")
        self.day_simple.geometry("600x400+400-500")
        self.day_simple.resizable(False, False)  # 크기 고정

        self.search_btn = tkinter.Button(self.day_simple, text = "검색", width = 10, height = 2, command = self.btn_search)
        self.search_btn.place(relx = 0.4, rely = 0.6)

        self.label_start_day = tkinter.Label(self.day_simple, text = "시작일 : (YYYYMMDD)", width = 20)
        self.label_start_day.place(relx = 0.15, rely = 0.1)
        self.entry_start_day = tkinter.Entry(self.day_simple, width = 20)
        self.entry_start_day.place(relx = 0.4, rely = 0.1)
        self.label_end_day = tkinter.Label(self.day_simple, text="종료일 : (YYYYMMDD)", width=20)
        self.label_end_day.place(relx=0.15, rely=0.2)
        self.entry_end_day = tkinter.Entry(self.day_simple, width=20)
        self.entry_end_day.place(relx=0.4, rely=0.2)
        self.label_city_num = tkinter.Label(self.day_simple, text="지역 번호", width=20)
        self.label_city_num.place(relx=0.15, rely=0.3)
        self.entry_city_num = tkinter.Entry(self.day_simple, width=20)
        self.entry_city_num.place(relx=0.4, rely=0.3)

        self.test = tkinter.Button(self.day_simple, text = "test" ,width = 10)
        self.test.place(relx = 0.5, rely = 0.6)

        self.day_simple.mainloop()

    def close(self):  # 창 닫기
        self.day_simple.quit()
        self.day_simple.destroy()

    def btn_search(self): # 검색 버튼
        Day_Simple.st_day = self.entry_start_day.get()
        Day_Simple.en_day = self.entry_end_day.get()
        Day_Simple.city_num = self.entry_city_num.get()
        return Day_Simple.st_day, Day_Simple.en_day, Day_Simple.city_num # return 클래스 변수

여기서 return 한 값을 다른 클래스에서 가져와서 그대로 사용하고 싶습니다.

st_day, en_day, city_num 에 entry 값을 집어넣고 다른 클래스에서 활용하는게 궁금합니다.

1 답변

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

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

(ಠ_ಠ)
(ಠ‿ಠ)