Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 当我们已经给出了几何尺寸时,如何在Tkinter中调整页面大小_Python 2.7_Tkinter_Tkinter Canvas - Fatal编程技术网

Python 2.7 当我们已经给出了几何尺寸时,如何在Tkinter中调整页面大小

Python 2.7 当我们已经给出了几何尺寸时,如何在Tkinter中调整页面大小,python-2.7,tkinter,tkinter-canvas,Python 2.7,Tkinter,Tkinter Canvas,我是Tkinter编程新手,已经编写了这段代码。 我想要的是,当我点击开始对话时,一个新的页面,即“对话”应该显示出来,窗口应该调整到另一个几何坐标。我已经在最顶层的类“pythonApp”中给出了几何坐标,但无法在其他类(如“对话”页面)中调整窗口的几何坐标。你能告诉我如何调整“对话”页面的大小吗。 下面是我的代码。 ` 将Tkinter作为tk导入 从Tkinter导入标签,两个 导入时间 从PIL导入图像 从PIL导入ImageTk 导入ttk 从wx导入底部 将日期时间导入为dt 大字体

我是Tkinter编程新手,已经编写了这段代码。 我想要的是,当我点击开始对话时,一个新的页面,即“对话”应该显示出来,窗口应该调整到另一个几何坐标。我已经在最顶层的类“pythonApp”中给出了几何坐标,但无法在其他类(如“对话”页面)中调整窗口的几何坐标。你能告诉我如何调整“对话”页面的大小吗。 下面是我的代码。 ` 将Tkinter作为tk导入 从Tkinter导入标签,两个 导入时间 从PIL导入图像 从PIL导入ImageTk 导入ttk 从wx导入底部 将日期时间导入为dt 大字体=(“Verdana”,12)

class pythonApp(tk.tk):
定义初始化(self,*args,**kwargs):
tk.tk.\uuuuu初始化(self,*args,**kwargs)
自几何(“700x500”)
tk.tk.iconbitmap(self,default=“accenture.ico”)#用于更改标题栏图像
tk.tk.wm_标题(自我,“化身”)#设置标题
##现在创建一个包含所有内容的容器
容器=tk.框架(自身)
container.pack(side=“top”,fill=“both”,expand=True)
container.grid_rowconfigure(0,权重=1)
container.grid\u column配置(0,权重=1)
#创建一个包含框架的字典,这样当我们点击开始对话时,就会加载一个新的框架
self.frames={}
#这将在每一页上循环
对于F in(起始页、第一页、对话):
框架=F(容器,自身)
self.frames[F]=帧
frame.grid(行=0,列=0,sticky=“nsew”)
自显示帧(起始页)
#此函数将显示我们需要的框架
def显示画面(自身,续):
帧=自身帧[续]
frame.tkraise()#此函数将页面置于前面
###################################################时间弹性模块部分
类ElapsedTimeClock(标签):
定义初始化(自、父、*args、**kwargs):
Label.\uuuuu init\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
self.lastTime=“”
t=time.localtime()
self.zeroTime=dt.timedelta(小时=t[3],分钟=t[4],秒=t[5])
self.tick()
def勾选(自我):
#从电脑获取当前的本地时间
now=dt.datetime(1,1,1).now()
elapsedTime=now-self.zeroTime
time2=elapsedTime.strftime(“%H:%M:%S”)
#如果时间字符串已更改,请更新它
如果时间2!=self.lastTime:
self.lastTime=time2
self.config(text=time2)
#每200毫秒调用一次
#根据需要更新时间显示
#可能需要>200毫秒,但显示器会抖动
self.after(200,self.tick)
####################################时间结束弹性模块
########这是它的第一页
类起始页(传统框架):
定义初始化(自、父、控制器):
tk.Frame.\uuuu init\uuuuu(自,父)
label=tk.label(self,text=“Welcome”,font=“LARGE\u font”)
标签包装(pady=10,padx=10)
photo=tk.PhotoImage(file=“howcanihelp.gif”)
w=标签(自我,图像=照片)
w、 照片
w、 包()
###########开始按钮$$$$4
conversationbutton=tk.按钮(self,text='Start Conversation',高度=2,宽度=40,bg=“深蓝色”,fg=“白色”,
font=(“Arial”,10,“bold”),command=lambda:controller.show_frame(对话))
会话按钮包(padx=7,pady=7)
chatbutton=tk.按钮(self,text='Chat',高度=2,宽度=40,bg=“海军蓝”,fg=“白色”,
font=(“Arial”,10,“bold”),command=lambda:controller.show_frame(第一页))
chatbutton.pack(padx=7,pady=7)
''停止按钮=tk.按钮(self,text='Stop',高度=2,宽度=40,fg=“白色”,bg=“深蓝色”,
字体=(“Arial”,10,“粗体”))
停止按钮组件(padx=7,pady=7)“”
##################################聊天窗口的secound页面
类别第一页(传统框架):
定义初始化(自、父、控制器):
tk.Frame.\uuuu init\uuuuu(自,父)
#label=tk.label(self,text=“Chat Page”,font=“LARGE\u font”).place()
#标签包装(pady=10,padx=10)
时钟=ElapsedTimeClock(self,字体=('times',20,'bold')).place(x=475,y=350)
#时钟网格(行=1,列=1)
#clock.pack(填充=两者,扩展=1)
photo=tk.PhotoImage(file=“agent.gif”)
w=标签(自我,图像=照片)
w、 照片
w、 地点(x=435,y=50)
#w、 网格(行=0,列=1)
ChatLog=tk.Text(self,bd=0,bg=“白色”,height=“8”,width=“50”,font=“Arial”,)
#ChatLog.insert(结束,“连接到您的合作伙伴…”\n)
ChatLog.config(state=tk.DISABLED)
#将滚动条绑定到聊天窗口
scrollbar=tk.scrollbar(self,command=ChatLog.yview,cursor=“heart”)
ChatLog['yscrollcommand']=scrollbar.set
#创建发送消息的按钮
SendButton=tk.按钮(self,font=30,text=“Send”,width=“12”,height=5,bd=0,bg=“#FFBF00”,
activebackground=“#FACC2E”)
#SendButton=按钮(底部,font=30,text=“Send”,width=“12”,height=5,
#bd=0,bg=“#FFBF00”,activebackground=“#FACC2E”)
label=tk.label(self,text=“Chat”).pack()
def禁用条目(事件):
EntryBox.config(state=tk.DISABLED)
def压力动作(事件):
EntryBox.config(state=tk.NORMAL)
#单击操作()
#创建用于输入消息的框
EntryBox=tk.Text(self,bd=0,bg=“白色”,width=“29”,height=“5”,font=“Arial”)
EntryBox.bind(“,DisableEntry)
EntryBox.bind(“,按Action)
#将所有组件放置在屏幕上
阴囊
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()