Tkinter in fullscreen mode makes Text widget not work - python

When using Tkinter as a regular window, the text widget works as intended and can be typed in.
from Tkinter import *
root = Tk()
T = Text(root, height=2, width=30)
T.pack()
T.insert(END, "Just a text Widget\nin two lines\n")
mainloop()
However if we make this application fullscreen:
from Tkinter import *
root = Tk()
root.attributes("-fullscreen", True)
T = Text(root, height=2, width=30)
T.pack()
T.insert(END, "Just a text Widget\nin two lines\n")
mainloop()
And try to type in the textbox, it won't work and the keys will instead appear in the terminal. Why is this and is there a solutoin?

import tkinter as tk
from tkinter import *
root = tk.Tk()
root.overrideredirect(True)
root.overrideredirect(False)
root.attributes('-fullscreen',True)
canvas= Canvas(root)
canvas.create_text(300, 50,text="This is a window", fill="black", font=('Helvetica 15 bold'))
canvas.pack()
This seems to be working with me

Related

Python - Custom tkinter - component.setfocus() don't work with customtkinter component like CTkEntry

I have this code and focus dont work with customtkinter
from tkinter import *
import customtkinter as ctk
import sys
if len(sys.argv) > 1:
print("Tk Customized from Tom")
win = ctk.CTk()
win.geometry("750x250")
text = ctk.CTkTextbox(win, width=200, height=200)
text.pack()
text.insert(INSERT, "Hello World!")
entry = ctk.CTkEntry(win, width=100)
entry.pack()
entry.focus_set()
else:
print("Standard Tk ")
win = Tk()
win.geometry("750x250")
text = Text(win, width=30, height=10)
text.insert(INSERT, "Hello World!")
text.pack()
entry = Entry(win, width=30)
entry.pack()
entry.focus_set()
win.mainloop()
py testy.py -> Start standard Tkinter Focus is on Entry
py testy.py 1 -> Start with customtkinter objects Focus is NOT on Entry
How can get focus on CTkEntry ?

How to center text in text widget in tkinter

I have a text widget
from tkinter import *
root = Tk()
root.wm_title("cloth")
root.geometry("500x500")
l = Text(root, width=46, bg="White",relief = "solid", font="Arial 9",height=1,bd=1)
l.configure(state='normal')
l.configure(state='disabled')
l.grid(row=1, column=1)
I want to center text
but if I select then only the text is selected, no space is selected
You need add tag_configure("tag_name", justify='center') and tag_add("tag_name", "1.0", "end")
Here is the example
from tkinter import *
root = Tk()
root.wm_title("cloth")
root.geometry("500x500")
l = Text(root, width=46, bg="White",relief = "solid", font="Arial 9",height=1,bd=1)
l.tag_configure("tag_name", justify='center')
l.insert("1.0", "How to center text in text widget in tkinter ?")
l.tag_add("tag_name", "1.0", "end")
l.grid(row=1, column=1)
I think, no way to do it without adding spaces
import tkinter as tk
root = tk.Tk()
T1 = tk.Text(root)
T1.tag_configure("center", justify='center')
T1.insert(1.0, " ")
T1.tag_add("center", "1.0", "end")
T1.pack()
root.mainloop()

How can tkinter entry widget to "tab" automatically after certain digits/characters?

I am writing a python tkinter trying to have 2 entry widgets. After entering 5 digits in the first entry widget, I want the 6th digit could be jumped to next entry widget automatically. How can I rewrite it to make it come true?
import tkinter as tk
root=tk.Tk()
canvas1=tk.Canvas(root,width=400,height=400,bg='#FFFFFF')
canvas1.pack()
entry1=tk.Entry(root,width=8)
canvas1.create_window(10,100,window=entry1,anchor='nw')
entry1.focus_set()
entry1=tk.Entry(root,width=8)
canvas1.create_window(100,100,window=entry1,anchor='nw')
root.mainloop()
Entry validation is what you are looking for. Try the following code:
import tkinter as tk
def on_validate(P):
if len(P) == 5: # The 6th entry is taken up by the 2nd entry widget
entry2.focus_set()
return True
root = tk.Tk()
canvas1 = tk.Canvas(root, width=400, height=400, bg='#FFFFFF')
canvas1.pack()
entry1 = tk.Entry(root, width=8, validate="key")
entry1['validatecommand'] = (entry1.register(on_validate), '%P')
canvas1.create_window(10, 100, window=entry1, anchor='nw')
entry1.focus_set()
entry2 = tk.Entry(root, width=8)
canvas1.create_window(100, 100, window=entry2, anchor='nw')
root.mainloop()

how to fix the position of scrollbar of scrolledtext widget in tkinter?

i want to fix the postion of scrollbar of scrolledtext widget of tkinter.
i'am creating a chatbot where after every new message there is need to drag the scrollbar down to see conversation which has a bad impact.
here is the code of scrolledtext
self.conversation = ScrolledText.ScrolledText(self,
state='disabled',borderwidth=5,
highlightthickness=1,
bg='#15202b',fg='#16202A',
font=('Arial Bold',8))
self.conversation.grid(column=0, row=1, columnspan=2, sticky='nesw', padx=3, pady=3)
from tkinter import *
from tkinter import scrolledtext
root = Tk()
scroll_x = Scrollbar(root, orient="horizontal")
text = scrolledtext.ScrolledText(root, wrap=NONE)
text.config(xscrollcommand=scroll_x.set)
scroll_x.configure(command=text.xview)
text.pack(fill=X)
scroll_x.pack(fill=X)
for i in range(10000):
text.insert(END, str(i)+"\n")
text.see("end")
root.update()
root.mainloop()
The command you are looking for is see("end")
text.see("end")
root.update()

Setting focus to specific TKinter entry widget

I'd like to set the focus of my program to a specific entry widget so that I can start entering data straight-away - how can I do this?
My current code
from Tkinter import *
root = Tk()
frame=Frame(root,width=100,heigh=100,bd=11)
frame.pack()
label = Label(frame,text="Enter a digit that you guessed:").pack()
entry= Entry(frame,bd=4)
entry.pack()
button1=Button(root,width=4,height=1,text='ok')
button1.pack()
root.mainloop()
Use entry.focus():
from Tkinter import *
root = Tk()
frame=Frame(root,width=100,heigh=100,bd=11)
frame.pack()
label = Label(frame,text="Enter a digit that you guessed:").pack()
entry= Entry(frame,bd=4)
entry.pack()
entry.focus()
button1=Button(root,width=4,height=1,text='ok')
button1.pack()
root.mainloop()
I tried this way and it is ok
entry= Entry(root)
entry.focus()
entry.pack

Categories