【发布时间】:2013-12-11 00:08:33
【问题描述】:
所以我通过一个非常基础的教程来学习 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)
忽略我所有的蹩脚的 cmets,但是当我在 IDLE 中运行它时,它只是冻结了,我必须使用 xkill 来关闭它。
注释掉 mLabel_4 后,IDLE 不会崩溃。发生了什么事?
【问题讨论】:
标签: ubuntu python-2.7 ide python-idle