Main
import AppWindow as a
import tkinter as tk

def main():
    win = tk.Tk()   #윈도우창
    app = a.AppWin(win, '300x300+100+100')
    win.mainloop()

main()

 

 

 

AppWindow
import tkinter as tk
import bus_info.service as binfo

class AppWin(tk.Frame):#AppWin은 Frame(위젯을 배치하는 판)
    def __init__(self, root=None, geo=None): #root:Tk()객체 geo=창크기위치
        #fr = tk.Frame(self.root)
        super().__init__(root)  # 부모 생성자에 기본 윈도우 전달
        self.root = root  # 기본 윈도우를 멤버변수로 저장
        self.root.geometry(geo)  # 윈도우의 크기 및 위치 설정
        self.root.resizable(True, True)  # 윈도우의 가로, 세로 크기 재조정 가능으로 설정
        self.pack()
        self.service = binfo.BusService()  #버스 앱 기능이 구현된 서비스 객체 생성
        self.create_widgets()

    def create_widgets(self):  # 원하는 구성요소 부착
        self.title = tk.Label(self, text='버스 정보 앱')
        self.title.pack()
        self.inputData = tk.Entry(self, width=20)
        self.inputData.pack()
        self.btn1 = tk.Button(self, text='노선ID로검색', command=self.handle1) #command:이벤트 핸들러 등록 속성
        self.btn1.pack()
        self.btn2 = tk.Button(self, text='노선ID로경로검색', command=self.handle2)  # command:이벤트 핸들러 등록 속성
        self.btn2.pack()
        self.btn3 = tk.Button(self, text='버스명검색', command=self.handle3)  # command:이벤트 핸들러 등록 속성
        self.btn3.pack()
        self.btn4 = tk.Button(self, text='노선ID로정거장검색', command=self.handle4)  # command:이벤트 핸들러 등록 속성
        self.btn4.pack()
        self.content = tk.Label(self, text='')
        self.content.pack()

    def handle1(self):
        busId = self.inputData.get()
        res = self.service.getRouteInfoItem(busId)
        self.content.config(text=res)
        self.inputData.delete(0, tk.END)

    def handle2(self):
        busId = self.inputData.get()
        res = ''
        res_list = self.service.getRoutePathList(busId)
        if str(type(res_list)) == "<class 'str'>":
            res = res_list
        else:
            for i in res_list:
                res += i.__str__()+'\n'  #no:1(x, y)
        self.content.config(text=res)
        self.inputData.delete(0, tk.END)

    def handle3(self):
        busName = self.inputData.get()
        res = ''
        res_list = self.service.getBusRouteList(busName)
        if str(type(res_list)) == "<class 'str'>":
            res = res_list
        else:
            for i in res_list:
                res += i.__str__() + '\n'  # no:1(x, y)
        self.content.config(text=res)
        self.inputData.delete(0, tk.END)

    def handle4(self):
        busId = self.inputData.get()
        res = ''
        res_list = self.service.getStaionsByRouteList(busId)
        if str(type(res_list)) == "<class 'str'>":
            res = res_list
        else:
            for i in res_list:
                res += i.__str__() + '\n'  # no:1(x, y)
        self.content.config(text=res)
        self.inputData.delete(0, tk.END)

 

 

 

 

 

+ Recent posts