Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.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:can';t在图像标签上将文本向左对齐_Python_Tkinter_Photoimage - Fatal编程技术网

Python tkinter:can';t在图像标签上将文本向左对齐

Python tkinter:can';t在图像标签上将文本向左对齐,python,tkinter,photoimage,Python,Tkinter,Photoimage,我正在尝试将文本对齐到左上角(仅使用tkinter)。到目前为止,我试过的东西都不管用(锚、包、带有粘性“w”的网格),我不明白为什么。我正在处理几个类,标签位于定义为其父类的框架内。到目前为止,框架没有任何属性,当用户通过电路板选择一个单词时,此标签上的文本将被更新。当我添加很多单词(3-4行)时,它确实向上 self.__words_found = "" WordsContainer.IMAGE = tki.PhotoImage(file="words_con

我正在尝试将文本对齐到左上角(仅使用tkinter)。到目前为止,我试过的东西都不管用(锚、包、带有粘性“w”的网格),我不明白为什么。我正在处理几个类,标签位于定义为其父类的框架内。到目前为止,框架没有任何属性,当用户通过电路板选择一个单词时,此标签上的文本将被更新。当我添加很多单词(3-4行)时,它确实向上

        self.__words_found = ""
        WordsContainer.IMAGE = tki.PhotoImage(file="words_container2.png")
        self.__words_found_label = tki.Label(self.__parent,
                                             text=self.__words_found,
                                             font=("David", 18),
                                             image=WordsContainer.IMAGE,
                                             compound='center',
                                             justify='left',
                                             relief=tki.FLAT, height=105,
                                             width=500)
        self.__words_found_label.grid(row=0, column=0,
                                      sticky='w')

    def add_word(self, word):
        if self.__current_index == 0:
            self.__words_found = word
        else:
            self.__words_found = self.__words_found + ", " + word
        if self.__current_index > 0 and self.__current_index % 20 == 0:
            self.__words_found = self.__words_found + '\n' + word
        self.__words_found_label.config(text=self.__words_found)
        self.__current_index += 1
看起来是这样的:

阅读。据我所知,它将在图像旁边显示文本,而我希望文本在图像上并左对齐“希望文本在图像上并左对齐”:
.Label(…,anchor='w')
。您需要使用
Canvas
来保存图像和文本。