滚动条显示但不滚动动态创建的组合框窗口小部件

时间:2019-01-24 18:14:48

标签: python tkinter tkinter-canvas

我在标签框架上创建了一个画布,滚动条。使用按钮,在画布上动态创建组合框窗口小部件。但是滚动条滚动浏览动态创建的文件。

  from tkinter import *      
  from tkinter import ttk

  root = Tk()      
  root.geometry("1366x705+0+0")


  ExtRole_Dest_LF = ttk.LabelFrame(root, text='ExternalRoles', width =600)
  ExtRole_Dest_LF.place(relx=0.225, rely=0.113, relheight=0.376, relwidth=0.264)

  canvas=Canvas(ExtRole_Dest_LF,bg='#FFFFFF', height = 110, width = 335, scrollregion=(0,0,500,800))
  canvas.grid(column = 0, row = 0, sticky = 'news')
  canvas.grid_propagate(0)
  canvas.config(scrollregion=canvas.bbox("all"))


  vbar=Scrollbar(ExtRole_Dest_LF,orient=VERTICAL, command=canvas.yview)
  vbar.grid(row = 0, column = 1,  sticky='ns')
  canvas.configure(yscrollcommand=vbar.set)

  global System_Dest_row
  System_Dest_row = 1
  def fn_SystemDest():
      global System_Dest_row
      System_Dest_col = 0
      System_Dest_cb = ttk.Combobox(canvas, values=['a','s','d','g'], width=15)
      System_Dest_cb.grid(row=System_Dest_row, column=System_Dest_col, padx=10, pady = 5)
      deletebutton = Button(canvas, text="X")
      deletebutton.grid(row=System_Dest_row, column=System_Dest_col + 1, padx=10, pady = 5)
      System_Dest_row += 1

  AddButton = Button(root, text = 'Add', command =fn_SystemDest )
  AddButton.grid(column = 3,row = 3)

  root.mainloop()

我可以使滚动条在动态组合框窗口小部件中滚动

我可以通过其他任何方式来解决方案以滚动LabelFrame / Frame上的组合框窗口小部件

1 个答案:

答案 0 :(得分:1)

您无法使用<form> <fieldset> <legend>HMM</legend> <img src="https://i.imgur.com/65CeLdF.gif" align="right" style="padding: 8px;"> <div class="maintext">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ornare est sed libero pretium commodo. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nam commodo mollis turpis, fringilla vulputate erat elementum at. Maecenas ligula arcu, dignissim quis euismod at, molestie a magna. Donec semper commodo mi, sit amet gravida augue venenatis nec. Suspendisse eu sodales orci. Fusce ultricies ante ac luctus cursus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nullam nisl ligula, maximus vitae tincidunt et, interdum quis lectus. Donec rutrum ante ac dapibus pellentesque. Phasellus non congue ex. Integer luctus nunc.</div> <div class="info"><span>### - @.user</span></div> </fieldset> </form>滚动添加到画布的内容。画布只能滚动使用grid函数之一添加到画布的项目。