Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.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 未显示的框架上的画布_Python_Tkinter - Fatal编程技术网

Python 未显示的框架上的画布

Python 未显示的框架上的画布,python,tkinter,Python,Tkinter,我在tkinter的框架内有一个画布。框架有背景色,画布也有。但框架背景似乎覆盖了画布的颜色 如何增加帧背景的透明度,使画布可见 import Tkinter import tkMessageBox from Tkinter import * top = Tkinter.Tk() frame = Frame(top, width=1000, height=1000, background="bisque") frame.pack() bottomframe = Frame(top, wi

我在tkinter的
框架内有一个
画布
。框架有背景色,画布也有。但框架背景似乎覆盖了画布的颜色

如何增加帧背景的透明度,使画布可见

import Tkinter
import tkMessageBox
from Tkinter import *


top = Tkinter.Tk()

frame = Frame(top, width=1000, height=1000, background="bisque")
frame.pack()

bottomframe = Frame(top, width=1000, height=1000, background="red")
bottomframe.pack( side = BOTTOM )


def creatLayers(no_of_layers, max_nodes_in_each_layer, frame1=bottomframe):
    print 'here2'

    listLayerRect=[]
    listDelimiterRect=[]

    #The canvas is created here.
    mainCanvas=Tkinter.Canvas(frame1, bg="white", height=1000, width=1000)
    frame1.pack(side=LEFT)

    for i in range (0,no_of_layers):            
        print 'here3'

        x=15*i

        #rectangles that are being drawn on the canvas.
        mainCanvas.create_polygon(x,0,x+10,0,x+10,1000,x,1000, outline='gray', fill='gray', width=2)

#        listLayerRect.append(Tkinter.Canvas(frame1, bg="blue", height=1000, width=30))
#        listDelimiterRect.append(Tkinter.Canvas(frame1, bg="yellow", height=1000, width=30))


L1 = Label(frame, text="Layers")
E1 = Entry(frame, bd =8)
L2 = Label(frame, text="Layers2")

def helloCallBack(E=E1,):
   # tkMessageBox.showinfo( "Hello Python", "Hello World")
   k=int(E.get())
   print 'here'
   print k

   creatLayers(k,k)      

B = Tkinter.Button(frame, text ="Enter", command = helloCallBack)

B.pack(side=LEFT)
#L1.pack(side=LEFT)
E1.pack(side=LEFT)
#L2.pack(side=LEFT)

top.mainloop()

因此,基本上,当您在框中输入一个数字并按enter键时,将在红色部分(框架)中创建一个画布,并在该画布上绘制一个网格图案。基本上,有两个框架,顶部框架包含按钮和输入框,下部框架应该能够在内部创建的画布上绘制内容。

画布未显示的原因是您没有告诉它显示在
frame1
中,即您忘了
打包
(或
网格
,或
放置
)它,因此在此期间只需执行以下操作:

...
mainCanvas=Tkinter.Canvas(frame1, bg="white", height=1000, width=1000)
mainCanvas.pack()
...
现在,根据您从布局角度真正想要实现的目标,您可能需要更好地思考如何使用
pack
grid
pack

这是上面修正后的结果(在MacOSX上,Sierra)

单击
之前,请输入

单击
后,输入

一般来说,只要记住,如果一个框架不包含任何特定大小的小部件,它就会有一个空的主体。

它说:“如何使用
pack
grid
pack
”,但是
pack
的另一端可能是
place
或其他什么?