Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.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 Tkinter:将新小部件打包到其他小部件下面_Python_Python 2.7_Tkinter_Widget - Fatal编程技术网

Python Tkinter:将新小部件打包到其他小部件下面

Python Tkinter:将新小部件打包到其他小部件下面,python,python-2.7,tkinter,widget,Python,Python 2.7,Tkinter,Widget,我正在尝试打包文本和滚动条小部件下面的按钮 #!/usr/bin/python try: from Tkinter import * except ImportError: from tkinter import * class Chat(Frame): def __init__(self, master): Frame.__init__(self, master) self.pack(anchor=N, fill=BOTH) self.create_wi

我正在尝试打包文本和滚动条小部件下面的按钮

#!/usr/bin/python

try:
  from Tkinter import *
except ImportError:
  from tkinter import *

class Chat(Frame):
  def __init__(self, master):
    Frame.__init__(self, master)
    self.pack(anchor=N, fill=BOTH)
    self.create_widgets()
    self.count = 0

  def create_widgets(self):
    self.scrolly = Scrollbar(self)
    self.scrolly.pack(side=RIGHT, fill=Y)
    self.chattext = Text(self, borderwidth=5, yscrollcommand=self.scrolly.set)
    self.chattext.pack(side=LEFT)
    self.scrolly.config(command=Text.yview(self.chattext))
    self.button1 = Button(self, text="Add text", command=self.add_text)
    self.button1.pack()

  def add_text(self):
    self.count += 1
    self.chattext.insert("end", "%i\n" % self.count)
    self.chattext.update_idletasks()


def main():
  root = Tk()
  root.title("Test Chat Client")
  root.geometry("600x500")
  #root.resizable(0,0)
  app = Chat(root)

  root.mainloop()

if __name__ == "__main__":
  main()
这就是它看起来的样子

我希望按钮位于下方,而不是位于其他小部件之间

我尝试了以下方法:

self.button1.pack(after=self.scrolly)
self.button1.pack(after=self.chattext)
我怎样包装底部的按钮

另一个问题是滚动条不工作,当我尝试滚动时,什么也没有发生。 (是的,我试着用很多行填充文本小部件,超出了它的查看范围。)


另外,为什么滚动条在远离文本小部件的地方查看/打包?

尝试改用网格几何体管理器


< P>我认为你应该考虑用字段替换文本字段。 它更易于使用,不需要手动放置滚动条。 (不要使用
pack
来放置它。使用
grid


非常感谢。现在一切都在正确的位置,我设法修复了滚动条。
import tkinter as tk
import tkinter.scrolledtext as tkst

self.chattext = tkst.ScrolledText(
    master = self,
    wrap   = tk.WORD,
    width  = 20,
    height = 10
)