简体   繁体   English

Python,选项卡内的 tkinter 按钮不与网格间隔

[英]Python, tkinter buttons within tab not spacing with grid

I attempting to design a "toolbox" or application/script launcher for quick script execution for our team.我试图为我们的团队设计一个“工具箱”或应用程序/脚本启动器,以便快速执行脚本。 I landed on Python with tkinter to design the GUI.我使用 tkinter 使用 Python 来设计 GUI。 I am inexperienced with GUI building and struggling to get the grid function to work within tkinter tabs.我对 GUI 构建缺乏经验,并且正在努力使网格功能在 tkinter 选项卡中工作。

Below is my code so far...以下是我到目前为止的代码......

import tkinter as tk
from tkinter import filedialog, Text, ttk
import os

root  = tk.Tk()
root.title("IT Toolbox")
root.iconbitmap('//fs02/IT/Scripts/IT Toolbox/bs.ico')
root.minsize(600, 700)

#Define Functions
def adminpwsh():
os.startfile("C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")
def fncmd():
os.startfile("C:/Windows/System32/cmd.exe")

#Defines Tab Space
tabControl = ttk.Notebook (root)

#Define HOME tab
tabMain = ttk.Frame (tabControl)
tabControl.add (tabMain, text = 'Home')

btnPowershell = tk.Button(tabMain, text ="Powershell", bg='#0F861B', fg='#FFFFFF', font=12, padx=2,                 pady=2, command=adminpwsh)
btnPowershell.grid(column=1, row=4)

btnCommand = tk.Button(tabMain, text ="Command", bg='#0F861B', fg='#FFFFFF', font=12, padx=6, pady=2, command=fncmd)
btnCommand.grid(column=1, row=12)

grid_columnconfigure()

#Define tab2
TabAD = ttk.Frame (tabControl)
tabControl.add (TabAD, text = "tab2")


#Define tab3
TabWU = ttk.Frame (tabControl)
tabControl.add (TabWU, text = "tab3")

#Defines pack for all tabs
tabControl.pack(expan = 1, fill = "both")

Right now the buttons on the tab are all clustered in the top left of the tab and I cannot position them where I want within the tab.现在选项卡上的按钮都聚集在选项卡的左上角,我无法将它们放置在选项卡中我想要的位置。 Any suggestions would be greatly appreciated!任何建议将不胜感激!

import tkinter as tk
from tkinter import filedialog, Text, ttk
import os

root  = tk.Tk()
root.title("IT Toolbox")
# root.iconbitmap('//fs02/IT/Scripts/IT Toolbox/bs.ico')
root.minsize(600, 500)

#Define Functions
def adminpwsh():
    os.startfile("C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")
def fncmd():
    os.startfile("C:/Windows/System32/cmd.exe")

#Defines Tab Space
tabControl = ttk.Notebook (root)

#Define HOME tab
tabMain = ttk.Frame (tabControl)
tabControl.add (tabMain, text = 'Home')

btnPowershell = tk.Button(tabMain, text ="Powershell", bg='#0F861B', fg='#FFFFFF', font=12, padx=2,                 pady=2, command=adminpwsh)
btnPowershell.grid(column=1, row=4)

btnCommand = tk.Button(tabMain, text ="Command", bg='#0F861B', fg='#FFFFFF', font=12, padx=6, pady=2, command=fncmd)
btnCommand.grid(column=1, row=12)

root.columnconfigure(0)

#Define tab2
TabAD = ttk.Frame (tabControl)
tabControl.add (TabAD, text = "tab2")


#Define tab3
TabWU = ttk.Frame (tabControl)
tabControl.add (TabWU, text = "tab3")

#Defines pack for all tabs
tabControl.pack(expan = 1, fill = "both")

root.mainloop()

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

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