text-widget

Is there a way to rotate text around (or inside) a circle?

半城伤御伤魂 提交于 2020-04-13 16:58:48
问题 typical spinning wheelI am making a spinning wheel in Python tKinter. Usually, when you spin the wheel, you land on a random slice on the wheel, where the random choice is the text displayed on the slice. I am unable to find a way to rotate text on the slices. I have tried to use the angle option in the create_text function , only it rotates the text around the center of the circle: for x in range(len(spinList)): color = "#"+("%06x"%random.randint(0,16777215)) c.create_arc(xy, start=90+((360

Horizontal scrollbar on Text widget not working

…衆ロ難τιáo~ 提交于 2020-01-16 11:59:42
问题 I have a small program that loads one or more iterations of a long string into a text field. I have set up a horizontal scrollbar to let me move across very long strings of text. I think I have everything set up between the text widget and the scrollbar (at least it looks like other code I have for a vertical scrollbar which works) but the scrollbar appears to be inactivated. No matter how long the text gets, it basically doesn't work. Everything else about this code appears to work, except

How to send subprocess text output to a Tkinter text widget?

孤人 提交于 2019-12-20 07:16:09
问题 import subprocess import os import time from tkinter import * root=Tk() textbox=Text(root) textbox.pack() def redirector(inputStr): textbox.insert(INSERT, inputStr) def address_ping(): ''' DOCSTRING -> Ip addresses in servers.txt are 192.168.0.1 192.168.0.26 ''' while True: with open('servers.txt', 'r') as f: for ip in f: result=subprocess.Popen(["ping", "-c", "7", "-n", "-W", "2", ip],stdout=f, stderr=f).wait() if result: print("ip address " + ip, "is inactive") sys.stdout.write = redirector

Tkinter: set StringVar after <Key> event, including the key pressed

余生颓废 提交于 2019-12-12 04:47:42
问题 Every time a character is entered into a Text widget, I want to get the contents of that widget and subtract its length from a certain number (basically a "you have x characters left" deal). But the StringVar() is always one event behind. This is, from what I gather, because the event is processed before the character is entered into the Text widget. This means that if I have 3 characters in the field and I enter a 4th, the StringVar is updated but is still 3 characters long, then it updates

How to send subprocess text output to a Tkinter text widget?

心已入冬 提交于 2019-12-02 10:23:41
import subprocess import os import time from tkinter import * root=Tk() textbox=Text(root) textbox.pack() def redirector(inputStr): textbox.insert(INSERT, inputStr) def address_ping(): ''' DOCSTRING -> Ip addresses in servers.txt are 192.168.0.1 192.168.0.26 ''' while True: with open('servers.txt', 'r') as f: for ip in f: result=subprocess.Popen(["ping", "-c", "7", "-n", "-W", "2", ip],stdout=f, stderr=f).wait() if result: print("ip address " + ip, "is inactive") sys.stdout.write = redirector else: print("ip address " + ip, "is active") sys.stdout.write = redirector pass address_ping() root

How to clear/delete the contents of a Tkinter Text widget?

核能气质少年 提交于 2019-11-28 09:41:14
I am writing a Python program in TKinter on Ubuntu to import and print the name of files from particular folder in Text widget. It is just adding filenames to the previous filnames in the Text widget, but I want to clear it first, then add a fresh list of filenames. But I am struggling to clear the Text widget's previous list of filenames. Can someone please explain how to clear a Text widget? Screenshoot and coding is giving below: import os from Tkinter import * def viewFile(): path = os.path.expanduser("~/python") for f in os.listdir(path): tex.insert(END, f + "\n") if __name__ == '__main__

How can you mark a portion of a text widget as readonly?

a 夏天 提交于 2019-11-27 22:36:37
How can I mark a portion of a tkinter text widget as readonly? That is, I want to be able to allow editing only in certain parts of the widget. For example, I want to allow editing only after a prompt but not before, to simulate a console. The most bullet-proof solution is to intercept the low-level insert and delete commands, and put logic in there to prevent insertions and deletions based on some sort of criteria. For example, you could disallow edits within any range of text that has the tag "readonly". Here's an example of this technique. It takes advantage of the fact that all insertions

Tkinter: set StringVar after <Key> event, including the key pressed

那年仲夏 提交于 2019-11-27 09:08:25
Every time a character is entered into a Text widget, I want to get the contents of that widget and subtract its length from a certain number (basically a "you have x characters left" deal). But the StringVar() is always one event behind. This is, from what I gather, because the event is processed before the character is entered into the Text widget. This means that if I have 3 characters in the field and I enter a 4th, the StringVar is updated but is still 3 characters long, then it updates to 4 when I enter a 5th character. Is there a way to keep the two in line? Here's some code. I removed

How to clear/delete the contents of a Tkinter Text widget?

我与影子孤独终老i 提交于 2019-11-27 02:31:49
问题 I am writing a Python program in TKinter on Ubuntu to import and print the name of files from particular folder in Text widget. It is just adding filenames to the previous filnames in the Text widget, but I want to clear it first, then add a fresh list of filenames. But I am struggling to clear the Text widget's previous list of filenames. Can someone please explain how to clear a Text widget? Screenshoot and coding is giving below: import os from Tkinter import * def viewFile(): path = os

How can you mark a portion of a text widget as readonly?

拟墨画扇 提交于 2019-11-26 23:11:11
问题 How can I mark a portion of a tkinter text widget as readonly? That is, I want to be able to allow editing only in certain parts of the widget. For example, I want to allow editing only after a prompt but not before, to simulate a console. 回答1: The most bullet-proof solution is to intercept the low-level insert and delete commands, and put logic in there to prevent insertions and deletions based on some sort of criteria. For example, you could disallow edits within any range of text that has