1
目的: 我想创建一个具有“选项卡”(显示的信息可以根据选定的选项卡改变的)屏幕的一部分的图形用户界面,和另一部分不断显示相同的东西。蟒蛇Tkinter制表符和画布
import ttk
import Tkinter
def demo():
#root = tk.Tk()
schedGraphics = Tkinter
root = schedGraphics.Tk()
root.title("Testing Bot")
universal_height = 606
canvas = schedGraphics.Canvas(root,width = 900, height = universal_height)
nb = ttk.Notebook(root)
# adding Frames as pages for the ttk.Notebook
# first page, which would get widgets gridded into it
page1 = ttk.Frame(nb,width = 300,height = universal_height)
# second page
page2 = ttk.Frame(nb,width = 300,height = universal_height)
nb.add(page1, text='One')
nb.add(page2, text='Two')
#
nb.grid()
day_label = schedGraphics.Label(page1, text="Day1:")
day_label.pack()
day_label.place(x=0, y=30)
day_label = schedGraphics.Label(page2, text="Day2:")
day_label.pack()
day_label.place(x=0, y=30)
canvas.create_rectangle(50,500,300,600,fill = "red")
canvas.grid()
root.mainloop()
if __name__ == "__main__":
demo()
问题:
在当前配置的翼片位于屏幕的未在左侧的中部。
如果我将canvas.grid()更改为canvas.pack()它实际上并不打开任何窗口?
画布上的矩形没有出现!
谢谢。
点#1是误导。例如,你说要使用第0列,但使用第1列。第二,仅仅因为它位于最左边的列中,不能保证它与窗口的左边缘相对。 –
@BryanOakley对不起,由于指出了错字。对于第二点,到目前为止,我的意思是笔记本电脑和边缘之间没有任何东西,但不一定会卡住它。 – TrakJohnson
谢谢@TrakJohnson!完美的答案,正是我想要的。后续问题:假设我想要一个矩形画在选项卡上(我可以拖动到画布上)。我已经有了拖动代码在画布上工作,但我无法在“选项卡”上绘制任何矩形 – smarttylerthecreator