tkinter

Set the same width to an entry and text tkinter label

蹲街弑〆低调 提交于 2021-01-28 04:09:47
问题 I would like to put an entry and a text label one under the other and with the same width. Here is my code : from tkinter import * root = Tk() title = StringVar() title_entry = Entry(root, textvariable=title, width=30) title_entry.pack() content_text = Text(root, width=30) content_text.pack() root.mainloop() But my 2 widgets don't have the same width. Any idea to solve it ? 回答1: The widgets are different sizes probably because they have different default fonts. If they have the same fonts and

Python Tkinter canvas class inheritance

守給你的承諾、 提交于 2021-01-28 03:34:55
问题 Using Tkinter 8.6, Python 3.7.3: A friendly user here instructed me on how to have an image act like a button by the way of creating an Imgbutton class that is a subclass of Tkinter Canvas . I have some questions regarding this code, here is the simplified version of it: #!/usr/local/bin/python3 import tkinter as tk from PIL import Image, ImageTk class Imgbutton(tk.Canvas): def __init__(self, master=None, image=None, command=None, **kw): super(Imgbutton, self).__init__(master=master, **kw)

Tkinter - Checking if application has focus

▼魔方 西西 提交于 2021-01-28 03:31:15
问题 I'm trying to subclass Tk where it pauses audio if and only if the entire application loses focus (i.e. the Tk instance loses focus and focus wasn't passed to a Toplevel or messagebox widget). I managed to get it sort-of working with a 'hack' - when a messagebox is open, it is the last child of the Tk instance and also has no children. Here is what I've tried: class TkWin(Tk): def __init__(self, title): super().__init__(className=title, baseName=title) self.bind('<FocusOut>', lambda event:

Tkinter Matplotlib, backend conflict?

旧巷老猫 提交于 2021-01-28 02:25:16
问题 I'm quite new to python but I've spent my last week trying to code a software to visualize some weavy thingy. The basic cinematic is: the user enters every information needed into a GUI then click proceed and I have an other big function to genereate all the graphics. This was working but the problem was that when I ran the function, which lasts like 2 minutes, the tkinter window was freezing. I read that I should use threads. Then I found this: http://uucode.com/texts/pylongopgui/pyguiapp

Proper Use Of Inheritance in Tkinter using Button widget

二次信任 提交于 2021-01-28 00:50:51
问题 I am writing a GUI in Tkinter using Python 2.11 using an OOP approach and trying to learn inheritance. I wrote a child class called ButtonField which is inherited from tk.Button. Inside ButtonField I have a method called pressMe which changes the color and text of the button when pressed. My eventual goal is to have more buttons in the GUI and all the associated methods contained in the ButtonField class for cleaner and more manageable code. When I press the Button the text "In Press Me

Where can I find the source code for the _tkinter module?

可紊 提交于 2021-01-28 00:17:41
问题 According to the Python 3 documentation, Chapter 25.1: tkinter - Python interface to Tcl/Tk: The Tk interface is located in a binary module named _tkinter . This module contains the low-level interface to Tk Where can I obtain the source code of this module? I checked python/cython on GitHub, but could not find it. 回答1: Found it here on GitHub for cpython 回答2: Check also this answer here which is related to your problem and gives this source (https://hg.python.org/cpython/file/3.6/) from

Is there a way to change height of tkinter Treeview heading?

对着背影说爱祢 提交于 2021-01-27 22:57:06
问题 I got a problem with changing the height of the Treeview.heading . I have found some answers about the dimensions of Treeview.column , but when I access Treeview.heading in the documentation, there is not a single word about changing the height of the heading dynamically when the text doesn't fit (and wrapping it) or even just hard-coding height of the heading in pixels. I don't have to split the text to two rows, but when I just keep it that long the whole table (as it has many entries)

py to exe : failed to execute script pyi_rth_win32comgenpy

风流意气都作罢 提交于 2021-01-27 21:54:37
问题 I'm creating a simple calculation program using tkinter module and want to convert to exe as I want it to be executable at any pc. But somehow the error message show (failed to execute script pyi_rth_win32comgenpy). I've try used pyinstaller ( cmd and the one on GitHub at : https://github.com/brentvollebregt/auto-py-to-exe) but to no avail. I also try using both types of python file (.py and .pyw) from tkinter import * from tkinter.filedialog import askopenfilename import pandas as pd from

tkinter - Change color of a disabled entry widget

眉间皱痕 提交于 2021-01-27 21:50:32
问题 Is there a way that I could change a color of disabled entry widget in python? x = tk.Entry(parent) x.configure({"background": "gray24"}) x.configure({"fg": "white"}) x.configure({"state": "disable"}) The code above only works when the "state" of the widget is "normal". 回答1: Set the entry widget's disabledbackground attribute. x.configure({"disabledbackground": "newcolour"}) Where "newcolour" is the colour you want to see when the entry widget is disabled. You can also use disabledforeground

Tkinter Matplotlib, backend conflict?

北慕城南 提交于 2021-01-27 20:30:27
问题 I'm quite new to python but I've spent my last week trying to code a software to visualize some weavy thingy. The basic cinematic is: the user enters every information needed into a GUI then click proceed and I have an other big function to genereate all the graphics. This was working but the problem was that when I ran the function, which lasts like 2 minutes, the tkinter window was freezing. I read that I should use threads. Then I found this: http://uucode.com/texts/pylongopgui/pyguiapp