Tkinter Text widget scroll bar doesn't show the first character - python

I am trying to make a horizontal scroll bar for a text widget in tkinter, it works but when the text is long, it starts not showing some parts of the first character untill it's totally disappeared.
You can see some pixels of the first character in this image
That's my code:
scrollbar = Scrollbar(window, orient='horizontal')
scrollbar.pack(side=BOTTOM, fill=X)
text = Text(window, font=("Calibri", 40), xscrollcommand=scrollbar.set)
text.tag_configure("center", justify='center')
text.insert("1.0", "222222222222222222222222222222")
text.tag_add("center", "1.0", "end")
text.config(width=100, height=1, background="#f2f2f2", borderwidth=0, state='disabled', wrap='none')
text.pack(pady=24)
scrollbar.config(command=text.xview)

I changed root.resizable(280, 20), try this:
from tkinter import*
root = Tk()
root.resizable(280, 20)
root.title("Scrollbar Widget Example")
scrollbar = Scrollbar(root, orient='horizontal')
scrollbar.pack(side=BOTTOM, fill=X)
text = Text(root, font=("Calibri", 40), xscrollcommand=scrollbar.set)
text.tag_configure("center", justify='center')
text.insert("1.0", "222222222222222222222222222222")
text.tag_add("center", "1.0", "end")
text.config(width=30, height=1, background="#f2f2f2", borderwidth=0, state='disabled', wrap='none')
scrollbar.config(command=text.xview)
text.pack(pady=24)
root.mainloop()

Related

why doesnt my label appear in my tkinter window when i use the RAISED relief but does appear when i use another relief?

from tkinter import *
window = Tk()
window.geometry("300x300")
window.config(background="red")
window.title("label")
photo = PhotoImage(file='photo_1.png')
label = Label(window,
text="hello world",
font=('Arial',40,"bold"),
fg="black",
bg="yellow",
relief=RAISED,
bd=10,
padx=20,
pady=20,
image=photo,
compound='bottom')`
label.pack()
window.mainloop()
when i use the RAISED relief, my label doesnt appear in my tkinter window. but when i change it to SUNKEN or FLAT relieves, it does appear.

how to add background just for text not for line in Tkinter python

I want to add background just for text not line . I work with Tkinter an text_widget
# text widget
self.text_widget = Text(self.window, width=10, height=50, bg='white', fg=TEXT_COLOR,
font=FONT, padx=20, pady=20, wrap=WORD,relief='raised')
self.text_widget.place(relheight=0.745, relwidth=0.98, rely=0.08)
self.text_widget.configure(cursor="arrow", state=DISABLED)
msg2 = f"{bot_name}: {healthcare}\n\n"
self.text_widget.configure(state=NORMAL)
self.text_widget.tag_config(tagName="respHealth", background="#2ECC71", foreground="black")
self.text_widget.insert(END, msg2, 'respHealth')
the problem I have
capture of backround

Centering button using grid() in tkinter

I am simply trying to center some buttons in Python and it won't work even after looking at other a dozen threads.
This is my code at the moment:
import tkinter as tk
HEIGHT = 600
WIDTH = 1000
root = tk.Tk()
canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()
frame = tk.Frame(root, bg='#000A01')
frame.place(relwidth=1, relheight=1)
button0 = tk.Button(frame, text="LEFT", relief='flat', justify='center', bg='#000A01', fg='#00A010', padx='35', width='0', font=('Monofonto', 18))
button0.grid(row=0, column=0)
button1 = tk.Button(frame, text="CENTER", relief='flat', justify='center', bg='#000A01', fg='#00A010', padx='35', width='0', font=('Monofonto', 18))
button1.grid(row=0, column=1)
button2 = tk.Button(frame, text="RIGHT", relief='flat', justify='center', bg='#000A01', fg='#00A010', padx='35', width='0', font=('Monofonto', 18))
button2.grid(row=0, column=2)
root.mainloop()
this is the output
outputofabovecode
I want all buttons to be centered in the middle of the window and if I were to add more buttons in the same row it would add more to the center.
To center a button using place:
place(relx=0.5, rely=0.5, anchor=CENTER).

How can I insert label in a scrollable canvas?

The scroll don't work at all. What's wrong in the code?
I'm using Python 2.7.16
I read that listbox and text widgets are used only for text. As I want to use labels, I'm trying to insert the labels in a frame, but as a Frame didn't scroll I decided to use a canvas. But I couldn't get it to work.
from Tkinter import *
root = Tk()
frame = Frame(root, width=300, height=200)
frame.grid(row=0, column=0)
canvas=Canvas(frame, bg='#FFFFFF', width=300, height=200, scrollregion=(0,0,500,500))
vbar = Scrollbar(frame, orient=VERTICAL)
vbar.pack(side=RIGHT, fill=Y)
canvas.config(width=300, height=250)
canvas.pack(side=LEFT, expand=True, fill=BOTH)
mylist = Frame(canvas, width=100)
for x in range(10):
texto = Label(mylist, text='CODE', bd=2, width=7, relief=RIDGE)
texto.grid(row=x, column=0)
texto1 = Label(mylist, text='EQUIPAMENT', bd=2, width=20, relief=RIDGE)
texto1.grid(row=x, column=1)
mylist.place(x=0, y=0)
vbar.config(command=canvas.yview)
canvas.config(yscrollcommand=vbar.set)
mainloop()

Text and entry width not the same tkinter

I'm starting to learn Tkinter library and I have a problem...
I use grid to set my window the way I want but I can't figure out how I can set the width of the entry widget the same as the text widget.
When I put the same number, I don't have the same width anyway...
Here is my code :
from tkinter import *
def click():
try:
output.delete(0.0,END)
entered_text=entry.get()
output.insert(END, entered_text)
except:
output.insert(END, "")
def reset():
output.delete(0.0,END)
entry.delete(0,END)
if __name__ == '__main__':
window = Tk()
window.title("TEST")
window.geometry("500x500")
Label (window, text="Nombre de palettes :").grid(row=0, sticky=W)
Label (window, text="Prix :").grid(row=1, sticky=W)
entry = Entry (window)
entry.grid(row=0, column=2)
output = Text(window, width=8, heigh=1, wrap=WORD)
output.grid(row=1, column=2)
accepter=Button(window, text="Accepter", width=6, command=click)
accepter.grid(row=2, column=0)
restart = Button(window, text="Reset", width=6,command=reset)
restart.grid(row=2, column=1)
fin = Button(window, text="Quitter", width=6,command=window.destroy)
fin.grid(row=2, column=2)
window.grid_columnconfigure(4, minsize=100)
window.mainloop()
Thank you in advance.
One way is to expand the widgets to fill the cell:
entry = Entry(window)
entry.grid(row=0, column=2, sticky=E+W, padx=10)
output = Text(window, width=8, heigh=1, wrap=WORD)
output.grid(row=1, column=2, sticky=E+W, padx=10)
Where sticky=E+W fills the cell horizontally, and then I add some padding padx=10 to get a distance from the cell limits.
If one of the widgets always is bigger you can let that widget determine the cell width and then just expand the other widget.

Categories

Resources