tkinter

ttk Menu wont unpost

痞子三分冷 提交于 2021-01-28 08:37:48
问题 I wanted to make a simple pop-up message that shows the name of the options represented as icons when the mouse enters them and hide when it leavs. This icons are images within buttons, and I have been able to show the message when entering the button using a Menu widget, but when the mouse leaves the button it dose NOT unpost, unless there's a klick. I tryed deleting the cascade, but the same happens, the difference is that he menu at that moment has no text. I tryed to .destroy() the menu

Python - How do I add a theme from ttkthemes package to a guizero application?

给你一囗甜甜゛ 提交于 2021-01-28 08:12:44
问题 I'm working on multiple guizero projects and I'm trying to add a theme from the Python package ttkthemes (arc to be exact). I have tried to add the theme to the app widget with the following code: from guizero import App, Text, PushButton from ttkthemes import ThemedStyle import tkinter.ttk as ttk app = App(title="App") style = ThemedStyle(app) style.set_theme("arc") text = Text(app, text="Text") button = PushButton(app, text="Button") app.display() And it doesn't show the theme This is what

Can't import tkinter (or Tkinter)

ε祈祈猫儿з 提交于 2021-01-28 08:06:00
问题 I am trying to import Tkinter to my project using Python 2.7 and instead I get the error: ImportError: No module named tkinter Before anyone says it, I have tried both "Tkinter" and "tkinter" but have gotten the exact same message. 回答1: First try using this code for your imports. try: import Tkinter as tk # this is for python2 except: import tkinter as tk # this is for python3 If this doesn't work, try reinstalling tkinter. If you don't know how to reinstall tkinter look at the tkinter

How can I remove newline character (\n) at the end of Text widget?

依然范特西╮ 提交于 2021-01-28 08:05:57
问题 I am working on a Tkinter GUI. I am wondering how can I remove newline character (\n) at the end of Text widget? It's making my App looking ugly I don't want this. Example code is: from tkinter import * from tkinter import ttk window = Tk() window.title('Advanced Calculator v0.9') window.geometry('500x400') window.resizable(False, False) window.configure(background='black') hist_t = Text(window, background='black', height='7', foreground='red', font='Verdana', highlightcolor='grey',

Getting values of dynamically generated Entry fields using Tkinter

依然范特西╮ 提交于 2021-01-28 07:12:37
问题 I've got a list of attributes such as cost, price, isObsolete etc. which I would like to dynamically generate as a label with an Entry field underneath, for the user to insert the correct value into. It seems the best way to do this is to store the attributes against the values in a dictionary, and update this dictionary whenever the Entry field is updated. I've tried used the trace_variable function on the StringVar assigned to my entry field, but it doesn't seem to when I type into the

tkinter: changing button attributes for buttons created in loop

假如想象 提交于 2021-01-28 07:09:52
问题 Right now this would work, but I would prefer to do it with for loops and a list. I've tried, but I cannot figure out how to get the name of the buttons that were created in the for loop. import tkinter as tk def toggle(button): #---------------------------- # Manages the button toggling #---------------------------- if button == 0: if button0.config('relief')[-1] == 'sunken': button0.config(relief='raised') else: button0.config(relief='sunken') if button == 1: if button1.config('relief')[-1]

Change cursor when doing a mouse event

最后都变了- 提交于 2021-01-28 07:07:59
问题 How to change the cursor for a mouse event (right click for example) in Python with Tkinter ? When I press the right click, the cursor is changing but when I release it, the cursor doesn't change. class App(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.new_width=800 self.new_height=600 # Main window self.fen = Tk() self.fen.title("Image") canevas = Canvas(self.fen, bd=0) ## creation of the canvas canevas.config(bg="white") canevas.config(cursor="dotbox") canevas

Python Tkinter random generating the colors?

≡放荡痞女 提交于 2021-01-28 06:50:18
问题 from tkinter import * import random tk = Tk() canvas = Canvas(tk, width=400, height=400) canvas.pack() for x in range(0, 40): x1 = random.randint(0,400) y1 = random.randint(0,400) x2 = random.randint(0,400) y2 = random.randint(0,400) x3 = random.randint(0,400) y3 = random.randint(0,400) my_triangle = canvas.create_polygon(x1, y1, x2, y2, x3, y3,\ fill =("blue"), outline="red") Hi! I am playing with tkinter and generating random triangles. The problem is: I want to use random on fill = " " to

tkinter: how to align a set of radio buttons that differs in text length

余生长醉 提交于 2021-01-28 06:39:04
问题 tech_radioButton1 = ttk.Radiobutton(selection_frame_1, text="ANT+", variable = self.tech_var, value = 1, command = self.tech_select) tech_radioButton1.pack(side = 'top') tech_radioButton2 = ttk.Radiobutton(selection_frame_1, text="Bluetooth", variable = self.tech_var, value = 2, command = self.tech_select) tech_radioButton2.pack(side = 'top') tech_radioButton3 = ttk.Radiobutton(selection_frame_1, text="BTLE", variable = self.tech_var, value = 3, command = self.tech_select) tech_radioButton3

How to handle Invalid command name error, while executing (“after” script) in tkinter python

落爺英雄遲暮 提交于 2021-01-28 06:24:08
问题 I know this question has been raised multiple times here and I have gone through all of them. But I didn't find a clear solution for the problem. I know the reasons for the occurrence of this error. I know that after using root.destroy() , there are still some jobs left to be completed and all that stuff. But I want to know how to stop those "after" jobs? One of the guys asked to use try / accept in the code. But he didn't show how to use that. So could you please give a clear solution for