Reputation: 3
So I am currently writing a program using python Tkinter where I enter details and it will enter each task on the same line. I left a photo of what I have done down below. I would like to have all of them print out on the same line.
I would like to have both 2s and the three buttons in the same line.
Here's my code
# This Python file uses the following encoding: utf-8
import os, sys
import tkinter as tk
from tkinter import *
from tkinter import ttk
import tkinter.font
import tkinter.messagebox
#Set up window
root = tk.Tk()
root.title("SNKRS Bot")
root.geometry("1000x600")
#Enter ID
IDHead = Label(root, text="ID:")
IDHead.grid(row=1, column=0)
IDInput = Entry(root, textvariable="", width='5')
IDInput.grid(row=1, column=1)
#Enter link
linkHead = Label(root, text="Link:")
linkHead.grid(row=2, column=0)
linkInput = Entry(root, textvariable="", width='60')
linkInput.grid(row=2, column=1)
ID = []
linkList = []
def createTask():
#Create variables for inputs
linkInput1 = linkInput.get()
IDInput1 = IDInput.get()
#Append to lists
linkList.append(linkInput1)
ID.append(IDInput1)
#print lists to check
print("ID: " + str(ID))
print("Links: " + str(linkList))
#Clear inputs
IDInput.delete(0, END)
linkInput.delete(0, END)
#Output values
# Label(root, text=(IDInput1 + " | " + linkInput1)).grid(column=0)
Label(root, text=linkInput1).grid(column=0)
Label(root, text=linkInput1).grid(column=1)
#Actions for each task
def startTask():
print("Task started")
def stopTask():
print("Task stopped")
def deleteTask():
print("Task deleted")
#Buttons for actions
startButton = tk.Button(root, text="start", command=startTask).grid(column=2)
stopButton = tk.Button(root, text="stop", command=stopTask).grid(column=3)
deleteButton = tk.Button(root, text="delete", command=deleteTask).grid(column=4)
#Create task
create = tk.Button(root, text="Create task", command=createTask)
create.grid(row=3, column=1)
root.mainloop()
Upvotes: 0
Views: 511
Reputation: 4537
I would like to have both two labels and the three buttons in the same line.
Your grid manager is messed up. Better start at row 0 instead of 1.
Change this to:
IDHead.grid(row=0, column=0)
IDInput.grid(row=0, column=1)
linkHead.grid(row=1, column=0)
linkInput.grid(row=1, column=1)
Label(root, text=linkInput1).grid(row=3,column=0 )
Label(root, text=linkInput1).grid(row=3,column=1)
startButton = tk.Button(...).grid(row=3,column=2)
stopButton = tk.Button(...).grid(row=3,column=3)
deleteButton = tk.Button(...).grid(row=3,column=4)
Screenshot:
Upvotes: 0
Reputation: 11
Whenever you are packing a label,in the grid method you are passing only the column.by doing so,it will pack the widget in a new row. To avoid that pass both the row and column arguments.
Ex: Label(root,text="some text").grid(row=3,column=0)
Upvotes: 1