我对python真的很陌生,目前我正在尝试使用tkinter设计一个表单。我一直试图在笔记本中插入滚动条和表单,因为我没有找到问题的答案,而且很简单“如何在笔记本 tkinter 小部件中插入滚动条和表单?”...如您所见,这对您来说很简单,但对于像我这样的新手来说却不是!
但是,这是我到目前为止所做的,幸运的是它确实显示了滚动条,但是当我尝试将表单插入笔记本时它崩溃了!
注意:我的 python 版本是带有 EPD_free 7.3-2(32 位)的 Python 2.7.3
import Tkinter
from Tkinter import *
from ttk import *
import tkMessageBox
import ttk
import Tkinter as tk
root = Tk()
root.title("Model_A")
root.resizable(0,0)
# start of Notebook (multiple tabs)
notebook = ttk.Notebook(root)
notebook.pack(fill=BOTH, expand=True)
notebook.pressed_index = None
#Child Frames
ContainerOne = Frame(notebook)
ContainerOne.pack(fill=BOTH, expand=True)
ContainerTwo = Frame(notebook)
ContainerTwo.pack(fill=BOTH, expand=True)
ContainerThree = Frame(notebook)
ContainerThree.pack(fill=BOTH, expand=True)
ContainerFour = Tkinter.Frame(notebook)
ContainerFour.pack(fill=BOTH, expand=True)
#Create the pages
notebook.add(ContainerOne, text='Mode A')
notebook.add(ContainerTwo, text='Mode B')
notebook.add(ContainerThree, text='Mode C')
notebook.add(ContainerFour, text='Mode D')
canvas = Canvas(ContainerOne, width=200, height=400)
scroll = Scrollbar(ContainerOne, command=canvas.yview)
canvas.config(yscrollcommand=scroll.set, scrollregion=(0,0,100,1000))
canvas.pack(side=LEFT, fill=BOTH, expand=True)
scroll.pack(side=RIGHT, fill=Y)
canvas = Canvas(ContainerTwo, width=200, height=400)
scroll = Scrollbar(ContainerTwo, command=canvas.yview)
canvas.config(yscrollcommand=scroll.set, scrollregion=(0,0,100,1000))
canvas.pack(side=LEFT, fill=BOTH, expand=True)
scroll.pack(side=RIGHT, fill=Y)
canvas = Canvas(ContainerThree, width=200, height=400)
scroll = Scrollbar(ContainerThree, command=canvas.yview)
canvas.config(yscrollcommand=scroll.set, scrollregion=(0,0,100,1000))
canvas.pack(side=LEFT, fill=BOTH, expand=True)
scroll.pack(side=RIGHT, fill=Y)
canvas = Canvas(ContainerFour, width=200, height=400)
scroll = Scrollbar(ContainerFour, command=canvas.yview)
canvas.config(yscrollcommand=scroll.set, scrollregion=(0,0,100,1000))
canvas.pack(side=LEFT, fill=BOTH, expand=True)
scroll.pack(side=RIGHT, fill=Y)
frame = Frame(canvas, width=200, height=1000)
canvas.create_window(100, 500, window=frame)
frameOne = None
def defocus(event):
event.widget.master.focus_set()
if __name__ == '__main__':
ContainerOne= Tkinter.Label(notebook, text=" 1. Enter Main Details: ", font=("fixedsys", "16","bold italic"))
frameOne.grid(row=2, columnspan=7, sticky='W', \
padx=5, pady=5, ipadx=5, ipady=5)
#Component Selection
componentComb= ttk.Combobox(ContainerOne, width="19")
componentComb = Combobox(ContainerOne, state="readonly", values=("A", "B", "C"))
componentComb.grid(column=4, row=4, columnspan="5", sticky="nswe")
componentComb.set("Main Selection")
root.mainloop()