2016-09-19 37 views
-1

對於Tkinter編程是新的並且已經編寫了這些代碼。 我想要的是,當我點擊開始對話時,應該顯示一個新的頁面,即「對話」,窗口應該調整到另一個幾何座標。我已經給出了最上面的類「pythonApp」中的幾何座標,但我無法使用幾何座標來調整其他類中的窗口,例如「對話」頁面。你能告訴我如何調整「對話」頁面嗎? 以下是我的代碼。 ' 進口Tkinter的從WX進口底部 進口日期時間作爲DT LARGE_FONT = tk的 從Tkinter的進口標籤,BOTH 導入時間 從PIL進口圖片 從PIL進口ImageTk 進口TTK ( 「宋體」,12)如何在Tkinter中調整頁面的大小時,我們已經給出了幾何尺寸

class pythonApp(tk.Tk): 
    def __init__(self, *args, **kwargs): 
     tk.Tk.__init__(self, *args, **kwargs) 
     self.geometry("700x500") 
     tk.Tk.iconbitmap(self, default="accenture.ico")     #this is for changing the title bar image 
     tk.Tk.wm_title(self,"Avatar")         #setting up the title 
     ##now creating a container which is going to contain everything 
     container = tk.Frame(self) 
     container.pack(side="top",fill="both",expand=True) 
     container.grid_rowconfigure(0, weight = 1) 
     container.grid_columnconfigure(0, weight = 1) 

     #creating a dictionary which willl contain frames so that when we click on Start Conversation a new frame will be loaded 
     self.frames = {} 

     #this will loop over every page 
     for F in (StartPage, PageOne,Conversation): 
      frame = F(container, self) 
      self.frames[F] = frame 

      frame.grid(row=0, column = 0 , sticky ="nsew") 
     self.show_frame(StartPage) 

#this function will show the frame that we need 
    def show_frame(self, cont): 
     frame = self.frames[cont] 
     frame.tkraise()# this function brings the page to the front 
###################################################section for time elasped module 


class ElapsedTimeClock(Label): 
    def __init__(self, parent, *args, **kwargs): 
     Label.__init__(self, parent, *args, **kwargs) 
     self.lastTime = "" 
     t = time.localtime() 
     self.zeroTime = dt.timedelta(hours=t[3], minutes=t[4], seconds=t[5]) 
     self.tick() 

    def tick(self): 
     # get the current local time from the PC 
     now = dt.datetime(1, 1, 1).now() 
     elapsedTime = now - self.zeroTime 
     time2 = elapsedTime.strftime('%H:%M:%S') 
     # if time string has changed, update it 
     if time2 != self.lastTime: 
      self.lastTime = time2 
      self.config(text=time2) 
     # calls itself every 200 milliseconds 
     # to update the time display as needed 
     # could use >200 ms, but display gets jerky 
     self.after(200, self.tick) 

####################################end of time elasped module 
########This is the 1st page which 
class StartPage(tk.Frame): 

    def __init__(self, parent, controller): 
     tk.Frame.__init__(self, parent) 
     label = tk.Label(self, text = "Welcome",font= "LARGE_FONT") 
     label.pack(pady=10, padx=10) 
     photo = tk.PhotoImage(file = "howcanihelp.gif") 
     w = Label(self, image=photo) 
     w.photo = photo 
     w.pack() 
     ###########start button$$$$4 
     conversationbutton = tk.Button(self, text='Start Conversation', height=2, width=40, bg="navy blue", fg="white", 
            font=("Arial", 10, "bold"),command=lambda:controller.show_frame(Conversation)) 
     conversationbutton.pack(padx=7, pady=7) 


     chatbutton = tk.Button(self, text='Chat', height=2, width=40, bg="navy blue", fg="white", 
          font=("Arial", 10, "bold"),command=lambda:controller.show_frame(PageOne)) 
     chatbutton.pack(padx=7, pady=7) 
     '''stopbutton = tk.Button(self, text='Stop', height=2, width=40, fg="white", bg="navy blue", 
          font=("Arial", 10, "bold")) 
     stopbutton.pack(padx=7, pady=7)''' 

##################################secound page for chat window 
class PageOne(tk.Frame): 

    def __init__(self, parent, controller): 
     tk.Frame.__init__(self, parent) 
     #label = tk.Label(self, text = "Chat Page",font= "LARGE_FONT").place() 
     #label.pack(pady=10, padx=10) 
     clock = ElapsedTimeClock(self, font=('times', 20, 'bold')).place(x=475,y=350) 
     #clock.grid(row = 1, column = 1) 
     #clock.pack(fill=BOTH, expand=1) 
     photo = tk.PhotoImage(file="agent.gif") 
     w = Label(self, image=photo) 
     w.photo = photo 
     w.place(x=435,y=50) 

     #w.grid(row = 0, column = 1) 
     ChatLog = tk.Text(self, bd=0, bg="white", height="8", width="50", font="Arial",) 
     # ChatLog.insert(END, "Connecting to your partner..\n") 
     ChatLog.config(state=tk.DISABLED) 

     # Bind a scrollbar to the Chat window 
     scrollbar = tk.Scrollbar(self, command=ChatLog.yview, cursor="heart") 
     ChatLog['yscrollcommand'] = scrollbar.set 

     # Create the Button to send message 
     SendButton = tk.Button(self, font=30, text="Send", width="12", height=5, bd=0, bg="#FFBF00", 
          activebackground="#FACC2E") 

     # SendButton = Button(base, font=30, text="Send", width="12", height=5, 
     #     bd=0, bg="#FFBF00", activebackground="#FACC2E") 
     label = tk.Label(self, text="Chat").pack() 

     def DisableEntry(event): 
      EntryBox.config(state=tk.DISABLED) 

     def PressAction(event): 
      EntryBox.config(state=tk.NORMAL) 
      # ClickAction() 

     # Create the box to enter message 
     EntryBox = tk.Text(self, bd=0, bg="white", width="29", height="5", font="Arial") 
     EntryBox.bind("<Return>", DisableEntry) 
     EntryBox.bind("<KeyRelease-Return>", PressAction) 

     # Place all components on the screen 
     scrollbar.place(x=376, y=6, height=386) 
     ChatLog.place(x=6, y=6, height=386, width=370) 
     EntryBox.place(x=128, y=401, height=90, width=265) 
     SendButton.place(x=6, y=401, height=90) 



     stopbutton1 = tk.Button(self, text='Stop', height=2, width=40, fg="white", bg="navy blue", 
           font=("Arial", 10, "bold"),command=lambda:controller.show_frame(StartPage)) 
     #stopbutton1.pack(padx=7, pady=7) 
     stopbutton1.place(x=399,y=401) 

############################################end of chat page 

class Conversation(tk.Frame): 

    def __init__(self, parent, controller): 
     tk.Frame.__init__(self, parent) 
     label = tk.Label(self, text = "Welcome",font= "LARGE_FONT") 
     label.grid(row=0, column=1 , columnspan=3) 
     photo = tk.PhotoImage(file = "agent.gif") 
     w = Label(self, image=photo) 
     w.photo = photo 
     #w.pack(side = tk.RIGHT) 
     w.grid(row=2,column=130 ,rowspan=3,columnspan=3,) 
     clock = ElapsedTimeClock(self, font=('times', 20, 'bold')) 
     #clock.pack() 
     clock.grid(row=3,column=3) 
     ###########start button$$$$4 
     stopbutton1 = tk.Button(self, text='Stop', height=2, width=40, fg="white", bg="navy blue", 
           font=("Arial", 10, "bold"), command=lambda: controller.show_frame(StartPage)) 
     #stopbutton1.pack(padx=7, pady=7) 
     #stopbutton1.grid(row=4,column=3) 
app = pythonApp() 
app.mainloop() 
+0

請閱讀http://www.stackoverflow.com/help/mcve。我不認爲你需要所有的代碼來重現這個問題。 –

回答

0

windowname.geometry( 「newsizexnewsize」)

相關問題