Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/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
Ubuntu 在Tkinter中使用行/列时,IDLE在基本操作系统上崩溃_Ubuntu_Python 2.7_Ide_Python Idle - Fatal编程技术网

Ubuntu 在Tkinter中使用行/列时,IDLE在基本操作系统上崩溃

Ubuntu 在Tkinter中使用行/列时,IDLE在基本操作系统上崩溃,ubuntu,python-2.7,ide,python-idle,Ubuntu,Python 2.7,Ide,Python Idle,所以我通过一个非常基础的教程来学习Tkinter。这是我目前的档案: import sys from Tkinter import * # Makes a variable and makes it an instance of the Tk() class mGui = Tk() # "500x500" is the dimensions. The other "+100+100" determines where the top left starts mGui.geometry("500

所以我通过一个非常基础的教程来学习Tkinter。这是我目前的档案:

import sys
from Tkinter import *
# Makes a variable and makes it an instance of the Tk() class
mGui = Tk()

# "500x500" is the dimensions. The other "+100+100" determines where the top left starts
mGui.geometry("500x500+100+100")

# Renames the window to "Learning GUI". Notice it isnt mGui.title = "Learning GUI"
mGui.title("Learning GUI")

# This will pack it automatically
"""mlabel = Label(text = "My Label").pack()"""

# This will pack it later, it's usually better. fg = foreground or text color in this case bg = background
# the Pack function places the object onto the center of the window.
mlabel = Label(text = "My Label 1", fg="red", bg="white")
mlabel.pack()
# Notice how it places it down under the original so they don't overlap.
# mlabel_2 = Label(text = "My Label", fg="red", bg="white")
# mlabel_2.pack()

# Here we are using place and placing it at the designated x and y values.
mlabel_2 = Label(text = "My Label 2", fg="red", bg="white")
mlabel_2.place(x=230, y=250)

#.grid is like creating a grid
mlabel_3 = Label(text = "My Label 3", fg="red", bg="white").grid(row = 0, column = 0)

mlabel_4 = Label(text = "My Label 4", fg="red", bg="white").grid(row = 1, column = 0)
忽略我所有的蹩脚评论,但当我在空闲状态下运行它时,它就会冻结,我必须使用xkill来关闭它


注释掉mLabel_4后,IDLE不会崩溃。发生了什么事?

我认为主要的问题是在同一个容器中混合了不同的几何体管理器。虽然这有时确实有效,但最好避免使用它并坚持使用.pack()、.grid()或.place()。因为tkinter会尝试一次完成所有的事情,失败的次数也会更多

另外,明确给父母贴标签也是个好主意。例如:

label = Label(mGui, text = text)
label.grid()

否则,默认情况下,小部件将被放置在最近提到的容器中

没有考虑它。。。混合包装和网格肯定是问题所在。除非你非常熟悉它们的工作原理,否则它几乎永远不会起作用。即使这样,也不建议这样做。