如何索引你的tkinter标签?

时间:2018-05-09 13:14:58

标签: python-3.x tkinter

我是python和tkinter的新手,在我的程序中我创建了多个标签并且运行良好,但我的问题是我需要稍后重新配置我的按钮,例如,如果按钮X单击然后更改第3标签颜色我和我的所有标签都有相同的名称 ll229 ,我试图使用像ll229 [3] .config这样的索引(做某事),但它没有用。

def update_ref_str():
  for i in range(ref_counter):

  ref_codes_str[i].set(ref_codes[i])
  ref_obj_per_codes_str[i].set(ref_obj_per_code[i])
  ref_time_needed_str[i].set(ref_time_needed_per_task[i])

  ll229 = Label(f2, textvariable = ref_codes_str[i] , bg='springgreen2',fg="gray23")
  ll229.config(font=("Helvetica", 13))
  ll229.place(bordermode=OUTSIDE, height=18, width=100, x=573, y=100 + 20*i )

  ll33 = Label(f2, textvariable = ref_obj_per_codes_str[i] , bg='springgreen2' , fg="gray23")
  ll33.config(font=("Helvetica", 13))
  ll33.place(bordermode=OUTSIDE, height=18, width=59, x=677, y=100 + 20*i)

  ll44 = Label(f2, textvariable = ref_time_needed_str[i] , bg='springgreen2',fg="gray23")
  ll44.config(font=("Helvetica", 13))
  ll44.place(bordermode=OUTSIDE, height=18, width=58, x=740 , y=(100 + 20*i))

1 个答案:

答案 0 :(得分:1)

这个问题显示了一个类似于你所使用的东西的例子,但是使用了入口小部件

example with entry widgets

或多或少 - 如果您设置了标签的名称,例如> [0664:26A0][2018-05-09T03:16:16]i000: > MainViewModel.OnPackageActionProgress: Percent completed: 50, Overall > progress: 3 [1830:047C][2018-05-09T03:16:16]e000: Error 0x800703f3: > Process returned error: 0x3f3 [1830:047C][2018-05-09T03:16:16]e000: > Error 0x800703f3: Failed to execute EXE package. > [0664:26A0][2018-05-09T03:16:16]e000: Error 0x800703f3: Failed to > configure per-machine EXE package. > [0664:26A0][2018-05-09T03:16:16]i000: MainViewModel.OnPackageAction: > Install Completed for package SQL Server Analysis Services (id: > Microsoft.DataTools.AnalysisServices) > [0664:26A0][2018-05-09T03:16:16]i319: Applied execute package: > Microsoft.DataTools.AnalysisServices, result: 0x800703f3, restart: > None [0664:26A0][2018-05-09T03:16:16]e000: Error 0x800703f3: Failed to > execute EXE package. [1830:047C][2018-05-09T03:16:16]i329: Removed > package dependency provider: Microsoft.DataTools.AnalysisServices, > package: Microsoft.DataTools.AnalysisServices > [1830:047C][2018-05-09T03:16:16]i351: Removing cached package: > Microsoft.DataTools.AnalysisServices, from path: > C:\ProgramData\Package Cache\9864EE5369359DB622D0234B6C6B7640B949140C\ > [0664:26A0][2018-05-09T03:16:16]i000: > MainViewModel.OnPackageActionProgress: Percent completed: 100, Overall > progress: 100 [1830:047C][2018-05-09T03:16:16]i372: Session end, > registration key: > SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{b5f086b7-5c95-4c1a-887b-f129b60d1f3b}, > resume: None, restart: None, disable resume: No > [1830:047C][2018-05-09T03:16:16]i330: Removed bundle dependency > provider: {b5f086b7-5c95-4c1a-887b-f129b60d1f3b} > [1830:047C][2018-05-09T03:16:16]i352: Removing cached bundle: > {b5f086b7-5c95-4c1a-887b-f129b60d1f3b}, from path: > C:\ProgramData\Package Cache\{b5f086b7-5c95-4c1a-887b-f129b60d1f3b}\ > [1830:047C][2018-05-09T03:16:16]i371: Updating session, registration > key: > SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{b5f086b7-5c95-4c1a-887b-f129b60d1f3b}, > resume: None, restart initiated: No, disable resume: No > [0664:26A0][2018-05-09T03:16:16]e000: MainViewModel.OnBundleAction: > Bundle action failed: Impossível abrir a chave de registo da > configuração (0x800703F3) [0664:26A0][2018-05-09T03:16:16]i399: Apply > complete, result: 0x800703f3, restart: None, ba requested restart: No > [0664:29B4][2018-05-09T03:21:56]i000: MainViewModel.OpenUrl: Opening > url: > C:\Users\LUSALM~1\AppData\Local\Temp\SsdtSetup\SSDT-Setup-PTB_20180509031104.log > [0664:29B4][2018-05-09T03:23:57]i000: MainViewModel.OpenUrl: Opening > url: > C:\Users\LUSALM~1\AppData\Local\Temp\SsdtSetup\SSDT-Setup-PTB_20180509031104.log ,则可以通过父框架name='l{}'.format(i)引用它们。

获取文字:

f2

同样,配置:

f2.children['l1'].get()