相互之间的所有小部件

时间:2019-06-06 14:32:02

标签: python user-interface tkinter

我正在做一个GUI项目(第一次使用tkinter)。我找不到与我的问题有关的任何东西,每个小部件都像彼此粘在一起一样。

我尝试更改padxpadyrowscolumn和其他一些东西。

import tkinter as tk
from Tkinter import *
vpn = tk.Tk()
#vpn.option_add("*Button.Background", "white")
#vpn.option_add("*Button.Foreground", "black")
vpn.title('testing')
vpn.geometry("630x360")
vpn.resizable(0, 0)
#main = tk.Frame(master=vpn,bg='grey')
#main.pack_propagate(0)
#main.pack(fill=tk.BOTH, expand=1)
variable = StringVar(vpn)
variable.set("Locations")
servers = OptionMenu(vpn, variable, "US", "CA", "RU", "UK", 'CH')
servers.grid(row=0, column=0, padx=195, pady=325)
close = tk.Button(vpn, text='Connect')
close.grid(row=0, column=0, padx=230, pady=325)

support = tk.Button(vpn, text='Help')
support.grid(row=0, column=0, padx=450, pady=325)
vpn.mainloop()

img

1 个答案:

答案 0 :(得分:0)

正如Henry Yik所说,您已将所有小部件放在<script src="https://cdn.ckeditor.com/ckeditor5/12.0.0/classic/ckeditor.js"></script> <div id="editor"> <h2>The three greatest things you learn from traveling</h2> <p>Like all the great things on earth traveling teaches us by example. Here are some of the most precious lessons I’ve learned over the years of traveling.</p> <h3>Appreciation of diversity</h3> <p>Getting used to an entirely different culture can be challenging. While it’s also nice to learn about cultures online or from books, nothing comes close to experiencing <a href="https://en.wikipedia.org/wiki/Cultural_diversity">cultural diversity</a> in person. You learn to appreciate each and every single one of the differences while you become more culturally fluid.</p> <h3>Confidence</h3> <p>Going to a new place can be quite terrifying. While change and uncertainty makes us scared, traveling teaches us how ridiculous it is to be afraid of something before it happens. The moment you face your fear and see there was nothing to be afraid of, is the moment you discover bliss.</p> </div> <div> <button type="button" id="change-height">Change Height</button> </div>的同一位置

您需要做的就是为每个小部件的行/列值设置不同的值,例如:

row=0, column=0

servers.grid(row=0, column=0, padx=195, pady=325) close.grid(row=0, column=1, padx=230, pady=325) support.grid(row=0, column=2, padx=450, pady=325) padx用于在小部件周围创建空白区域(“填充”),以使它们在放置时不会相互接触。

有3种不同的方式可以在tkinter中放置小部件:pady(这是您使用的方式),gridpackRead this,以获取有关如何使用它们的信息。