简体   繁体   English

如何允许Tkinter中的小部件跨向后跨多个列?

[英]How to allow a widget in Tkinter to span multiple columns going backwards?

I am recreating this: 我正在重新创建:

在此处输入图片说明

I'm trying to get the label 'Send to country's leader' to span two columns like in the picture, but going backward.This is my code for it: 我正在尝试使标签'Send to country's Leader'跨越图片中的两列,但往后走。这是我的代码:

from tkinter import *

countries = ['Belgium', 'Canada', 'China', 'Denmark', 'Finland', 'France', 'Greece',
             'India', 'Italy']

root = Tk()

countryBox = Listbox(root)
countryBox.config(relief=SUNKEN, border=2)
countryBox.grid(row=0, column=0, sticky='w')

for x in countries[::-1]:
    countryBox.insert(END, x)

Label(root, text="Send to country's leader:").grid(row=0, column=1, sticky='nw', columnspan=2)

This doesn't work though, since columnspan only works with columns following the one specified. 但是,这不起作用,因为columnspan仅适用于指定列之后的列。 How do I do it for ones before? 我该如何为以前的人做呢?

You can't span backwards. 你不能向后跨越。 However, you can move the item to the previous column and span forwards. 但是,您可以将项目移至上一列并向前扩展。 It gives exactly the same result. 它给出完全相同的结果。

In other words, putting a widget in column one and spanning backwards is exactly the same as putting it in column zero and spanning forwards. 换句话说,将小部件放在第一列并向后扩展与将其放在零列并向前扩展完全相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM