tkinter

i get this error “RuntimeError: threads can only be started once” when i click close and then click run again

对着背影说爱祢 提交于 2021-02-11 12:40:52
问题 import threading from tkinter import * running = False def run(): global running c = 1 running = True while running: print(c) c += 1 run_thread = threading.Thread(target=run) def kill(): global running running = False root = Tk() button = Button(root, text='Run', command=run_thread.start) button.pack() button1 = Button(root, text='close', command=kill) button1.pack() button2 = Button(root, text='Terminate', command=root.destroy) button2.pack() root.mainloop() click here for error img....i'm

Wack-A-Mole for school - Python

可紊 提交于 2021-02-11 12:40:51
问题 The command destroymole() is unable to run without mole = tk.Button(root, ...) , but mole can't run without destroymole() How can I get them to be defined for the other one at the same time? import tkinter as tk import random root = tk.Tk() canvas = tk.Canvas(root, height=600, width=700, bg="#4f75b3") canvas.pack() frame = tk.Frame(root, bg="#66bd5e") frame.place(relx=0.075,rely=0.075,relheight=0.85,relwidth=0.85,) def destroymole(): mole.destroy() mole = tk.Button(root, text="MOLE",relief=

i get this error “RuntimeError: threads can only be started once” when i click close and then click run again

…衆ロ難τιáo~ 提交于 2021-02-11 12:39:20
问题 import threading from tkinter import * running = False def run(): global running c = 1 running = True while running: print(c) c += 1 run_thread = threading.Thread(target=run) def kill(): global running running = False root = Tk() button = Button(root, text='Run', command=run_thread.start) button.pack() button1 = Button(root, text='close', command=kill) button1.pack() button2 = Button(root, text='Terminate', command=root.destroy) button2.pack() root.mainloop() click here for error img....i'm

tkinter using two keys at the same time

故事扮演 提交于 2021-02-11 12:37:57
问题 So tkinker can only use one key at a time. I am unable to say move to the left and up at the same time with this example. How would i go about doing it if I wanted to? import tkinter root = tkinter.Tk() root.title('test') c= tkinter.Canvas(root, height=300, width=400) c.pack() body = c.create_oval(100, 150, 300, 250, fill='green') def key(event): OnKeyDown(event.char) print(event.char) def MoveLeft(evenr) c.move(body, -10, 0) def MoveRight(event): c.move(body, 10, 0) def MoveUp(event): c.move

Automatically updating a value through a OptionMenu tkinter object

匆匆过客 提交于 2021-02-11 12:36:43
问题 I would like to write a tkinter app that will automatically update a value based on the current state of the OptionMenu object. Here's what I have so far from tkinter import * root = Tk() def show(): myLabel=Label(root,text=clicked.get()).pack() clicked=StringVar() clicked.set("1") drop = OptionMenu(root,clicked,"1","2","3") drop.pack() myButton = Button(root,text="show selection",command=show) root.mainloop() In this version, the text can only be updated by clicking a button. How can I make

Automatically updating a value through a OptionMenu tkinter object

走远了吗. 提交于 2021-02-11 12:33:54
问题 I would like to write a tkinter app that will automatically update a value based on the current state of the OptionMenu object. Here's what I have so far from tkinter import * root = Tk() def show(): myLabel=Label(root,text=clicked.get()).pack() clicked=StringVar() clicked.set("1") drop = OptionMenu(root,clicked,"1","2","3") drop.pack() myButton = Button(root,text="show selection",command=show) root.mainloop() In this version, the text can only be updated by clicking a button. How can I make

How do I display an extremly long image in Tkinter? (how to get around canvas max limit)

陌路散爱 提交于 2021-02-11 12:33:36
问题 I've tried multiple ways of displaying large images with tkinterreally long image No matter what I've tried, there doesn't seem to be any code that works. The main issue is that Canvas has a maximum height limit of around 30,000 pixels. Is there a way to display this whole image? increase, or get around the canvas limit? See the example image below. 回答1: There is no way around the size limit of the canvas, short of modifying and recompiling the underlying tk code. This would likely not be a

Functions in Tkinter

元气小坏坏 提交于 2021-02-11 12:33:30
问题 So I am practicing using Tkinter with python, and I am just trying to learn the basics. My code right now is import Tkinter as tk class Example(tk.Frame): def __init__(self, parent): tk.Frame.__init__(self, parent) self.prompt = tk.Label(self, text="Press a button", anchor="w") self.button1 = tk.Button(self, text="Button 1", command = self.button1) self.button2 = tk.Button(self, text="Button 2", command = self.button2) self.output = tk.Label(self, text="") # lay the widgets out on the screen.

Tkinter - Can I change the background color for a TTK Label set in ReadOnly mode? I tried but it didn't work

随声附和 提交于 2021-02-11 12:30:07
问题 In according with the TTK documentation, in my code, I tried to change the background color only for the TTK labes placed in readonly mode, but unfortunately it didn't work. I replicated the issue below: from tkinter import * from tkinter import ttk class MainWindow: def __init__(self): self.parent=Tk() self.parent.geometry("350x250") self.parent.title("Test") self.parent.configure(background="#f0f0f0") style=ttk.Style() # only the "foreground" option works, but the "background" one not. why?

Change color of one letter in label. Python

依然范特西╮ 提交于 2021-02-11 12:29:10
问题 I can change color of all text in label, but I want to change color of one letter. Is that possible? I use tkiner and python 3.3. 回答1: No, it is not possible to change the color of one letter in a label. However, you can use a text widget instead of a label to color just a single character. You could also use a canvas widget. 来源: https://stackoverflow.com/questions/22071505/change-color-of-one-letter-in-label-python