2017-02-21 5 views
1

이 GUI의 창 크기를 변경하려고했지만 고생하고 있습니다. root.geometry ("1080x800 + 200 + 200")를 사용하려고했지만 나던 한테 잘 작동하지 않는 것 같습니다. 왜 누군가가 설명 할 수 있습니까? 저는 현재 tkinter를 사용하여 연습하고 있습니다. 감사합니다GUI 창의 크기 변경 tkinter

import tkinter as tk # python3 
TITLE_FONT = ("Helvetica", 18, "bold") 

class SampleApp(tk.Tk): 

    def __init__(self, *args, **kwargs): 
     tk.Tk.__init__(self, *args, **kwargs) 

     # the container is where we'll stack a bunch of frames 
     # on top of each other, then the one we want visible 
     # will be raised above the others 
     container = tk.Frame(self) 
     container.pack(side="top", fill="both", expand=True) 
     container.grid_rowconfigure(0, weight=1) 
     container.grid_columnconfigure(0, weight=1) 

     self.frames = {} 
     for F in (StartPage, PageOne, PageTwo): 
      page_name = F.__name__ 
      frame = F(parent=container, controller=self) 
      self.frames[page_name] = frame 

      # put all of the pages in the same location; 
      # the one on the top of the stacking order 
      # will be the one that is visible. 
      frame.grid(row=0, column=0, sticky="nsew") 

     self.show_frame("StartPage") 

    def show_frame(self, page_name): 
     '''Show a frame for the given page name''' 
     frame = self.frames[page_name] 
     frame.tkraise() 


class StartPage(tk.Frame): 

    def __init__(self, parent, controller): 
     tk.Frame.__init__(self, parent) 
     self.controller = controller 
     label = tk.Label(self, text="This is the start page", font=TITLE_FONT) 
     label.pack(side="top", fill="x", pady=10) 

     button1 = tk.Button(self, text="Go to Page One", 
          command=lambda: controller.show_frame("PageOne")) 
     button2 = tk.Button(self, text="Go to Page Two", 
          command=lambda: controller.show_frame("PageTwo")) 
     button1.pack() 
     button2.pack() 


class PageOne(tk.Frame): 

    def __init__(self, parent, controller): 
     tk.Frame.__init__(self, parent) 
     self.controller = controller 
     label = tk.Label(self, text="This is page 1", font=TITLE_FONT) 
     label.pack(side="top", fill="x", pady=10) 
     button = tk.Button(self, text="Go to the start page", 
          command=lambda: controller.show_frame("StartPage")) 
     button.pack() 


class PageTwo(tk.Frame): 

    def __init__(self, parent, controller): 
     tk.Frame.__init__(self, parent) 
     self.controller = controller 
     label = tk.Label(self, text="This is page 2", font=TITLE_FONT) 
     label.pack(side="top", fill="x", pady=10) 
     button = tk.Button(self, text="Go to the start page", 
          command=lambda: controller.show_frame("StartPage")) 
     button.pack() 


if __name__ == "__main__": 
    app = SampleApp() 
    app.mainloop() 
+0

'root.geometry'가 무슨 뜻입니까? – WhatsThePoint

+0

나는 root.geometry를 사용하려했지만 창을 더 크게 만들지 않았다. 단지 내가 원하는 크기로 새 창을 만들었다. – saalahdin

+0

'root.geometry'는 tkinter 창 크기를 변경합니다. 파이썬 콘솔이 바뀌지 않는다는 것을 의미합니까? – WhatsThePoint

답변

3

root.geometry에 전화 할 수 없도록 프로그램에 루트가 선언되어 있지 않습니다. 코드를 이와 같이 변경하면 root.geometry을 호출하고 GUI 창 크기를 변경할 수 있으며 root을 사용하여 다른 페이지 클래스의 매개 변수로 전달하고 다른 모든 크기를 설정할 수 있습니다 당신이 원하는 경우.

if __name__ == "__main__": 
    root = tk.Tk() 
    root.geometry("1080x800+200+200") 
    app = SampleApp(root) 
    root.mainloop() 
+0

나는 바보 같아서 다른 프로그램에서 사용하고있다. 지금은 작동하지만, 방금 한 일을 대신한다. 'if __name__ == "__main__": app = SampleApp() app.geometry ("1080x800 + 200 + 200") app.mainloop()' – saalahdin

+0

이 예에서는 root를 만들고 싶지 않습니다. 'SampleApp' 서브 클래스는'Tk'이므로'app'에'geometry'를 호출하면됩니다. –

0

첫 번째 클래스 SampleApp에서는 self.geometry('500x555') #for example 만 사용할 수 있습니다.