Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.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
Tkinter 在';行不通_Tkinter_Python_Python 2.7_Layout - Fatal编程技术网

Tkinter 在';行不通

Tkinter 在';行不通,tkinter,python,python-2.7,layout,Tkinter,Python,Python 2.7,Layout,我是个新手。我试图在 0,0< /代码>左侧创建文本小部件,但是它出现在中间,就像默认的代码>包()/代码> 这是我的密码: from Tkinter import * # the ui of the main window class Ui(object): # the init of the client object def __init__(self): self.root = Tk() self.mid_height = self.

我是个新手。我试图在<代码> 0,0< /代码>左侧创建<代码>文本<代码>小部件,但是它出现在中间,就像默认的代码>包()/代码>

这是我的密码:

from Tkinter import *


# the ui of the main window
class Ui(object):
    # the init of the client object
    def __init__(self):
        self.root = Tk()
        self.mid_height = self.root.winfo_screenheight() / 2
        self.mid_width = self.root.winfo_screenwidth() / 2
        self.root.title("Journey-opening")
        self.root.geometry("600x600+{}+{}".format(self.mid_width - 300, self.mid_height - 300))
        self.root.resizable(width=0, height=0)
        self.cyan = "#0990CB"
        self.root["background"] = self.cyan
        self.frame = Frame(self.root)
        self.frame.pack()
        self.chat_box = Text(self.frame, height=30, width=50)
        self.chat_box.pack(side=LEFT)

    def open(self):
        self.root.mainloop()

wins = Ui()
wins.open()
我还尝试了
grid
方法,但它没有改变任何东西,还创建了另一个小部件,因为它可能至少需要两个小部件

我想这和我的框架有关,但我遵循一个教程,一切似乎都很好

“在侧面打包文本小部件不起作用”

这是不正确的。行
self.chat\u box.pack(side=LEFT)
Text
小部件打包到一边。只是它是在
self.frame
内部完成的,默认情况下,self.frame为它封装的小部件(在本例中,它只是文本小部件)分配了所需的空间。因此,在某种程度上,
文本
小部件是打包的,不仅仅是左边,而是四面八方


为了在左上角有
self.chat_box
,您应该让框架占据比所需更多的空间,在这种情况下,它可以简单地占据其父对象(
self.root
)内x轴上的所有空间。为此,请更换:

self.frame.pack()
与:

“在侧面打包文本小部件不起作用”

这是不正确的。行
self.chat\u box.pack(side=LEFT)
Text
小部件打包到一边。只是它是在
self.frame
内部完成的,默认情况下,self.frame为它封装的小部件(在本例中,它只是文本小部件)分配了所需的空间。因此,在某种程度上,
文本
小部件是打包的,不仅仅是左边,而是四面八方


为了在左上角有
self.chat_box
,您应该让框架占据比所需更多的空间,在这种情况下,它可以简单地占据其父对象(
self.root
)内x轴上的所有空间。为此,请更换:

self.frame.pack()
与: