tkinter

Tkinter button different commands on right and left mouse click

淺唱寂寞╮ 提交于 2021-01-28 11:10:04
问题 I am making minesweeper game in Python and use tkinter library to create gui. Is there any way to bind to tkinter Button two commands, one when button is right-clicked and another when it's left clicked? 回答1: Typically buttons are designed for single clicks only, though tkinter lets you add a binding for just about any event with any widget. If you're building a minesweeper game you probably don't want to use the Button widget since buttons have built-in behaviors you probably don't want.

Ideal way to config all the buttons of my Tkinter application at once?

与世无争的帅哥 提交于 2021-01-28 10:51:40
问题 This is my first tkinter/gui project. I set up a mvc pattern and have a view class for each window of my application. An example for the main window: class ViewMain(tk.Frame): def __init__(self, master): tk.Frame.__init__(self, master, height = 300, width = 500) self.pack(fill='both', expand=True) self.BUTTON_SIZE = {'relheight' : 0.3, 'relwidth' : 0.35} self._set_widgets() self._set_layout() def _set_widgets(self): self.button = tk.Button(self, text = 'Text') def _set_layout(self): self

Getting a _tkinter.TclError when I try to cut and paste in a custom tkinter text field

喜你入骨 提交于 2021-01-28 10:35:47
问题 I am working on a text editor using tkinter in python 3. I am having an issue with the custom text field class that I am using to attatch line numbers. It is from the answer from Brian Oakley to this question. Here is the code for the class: class CustomText(tk.Text): def __init__(self, *args, **kwargs): tk.Text.__init__(self, *args, **kwargs) # create a proxy for the underlying widget self._orig = self._w + "_orig" self.tk.call("rename", self._w, self._orig) self.tk.createcommand(self._w,

Getting a _tkinter.TclError when I try to cut and paste in a custom tkinter text field

不羁岁月 提交于 2021-01-28 10:34:23
问题 I am working on a text editor using tkinter in python 3. I am having an issue with the custom text field class that I am using to attatch line numbers. It is from the answer from Brian Oakley to this question. Here is the code for the class: class CustomText(tk.Text): def __init__(self, *args, **kwargs): tk.Text.__init__(self, *args, **kwargs) # create a proxy for the underlying widget self._orig = self._w + "_orig" self.tk.call("rename", self._w, self._orig) self.tk.createcommand(self._w,

How do you close all Tkinter windows when specific window closes?

感情迁移 提交于 2021-01-28 10:33:48
问题 I have this application in Python Tkinter. There is a Python file which is a main menu. When I click an option in the main menu it imports a python file with code that makes a new window (couldn't use Toplevel for the new window for some reasons). So when I close the main menu it should close all the other windows. Here is my code for the main menu: from tkinter import * root = Tk() root.geometry("600x600") def newWindowImport(): import file1 def newWindowImport2(): import file2 newWindow =

How do you close all Tkinter windows when specific window closes?

旧巷老猫 提交于 2021-01-28 10:24:35
问题 I have this application in Python Tkinter. There is a Python file which is a main menu. When I click an option in the main menu it imports a python file with code that makes a new window (couldn't use Toplevel for the new window for some reasons). So when I close the main menu it should close all the other windows. Here is my code for the main menu: from tkinter import * root = Tk() root.geometry("600x600") def newWindowImport(): import file1 def newWindowImport2(): import file2 newWindow =

Tkinter Button doesn´t change it´s relief after pressing it

时间秒杀一切 提交于 2021-01-28 10:02:27
问题 Why does my tkinter Button stays in the "sunken" relief after I press it? import tkinter from tkinter import messagebox as msgbox class GUI(object): def __init__(self): self.root = tkinter.Tk() self.root.geometry("200x200") self.root.title("Test") self.testButton = tkinter.Button(self.root, text="Click Me!") self.testButton.bind("<Button-1>", self.click) self.testButton.bind("<ButtonRelease-1>", self.release) self.testButton.pack() def release(self, event): event.widget.config(relief=tkinter

Tkinter Button doesn´t change it´s relief after pressing it

醉酒当歌 提交于 2021-01-28 10:00:14
问题 Why does my tkinter Button stays in the "sunken" relief after I press it? import tkinter from tkinter import messagebox as msgbox class GUI(object): def __init__(self): self.root = tkinter.Tk() self.root.geometry("200x200") self.root.title("Test") self.testButton = tkinter.Button(self.root, text="Click Me!") self.testButton.bind("<Button-1>", self.click) self.testButton.bind("<ButtonRelease-1>", self.release) self.testButton.pack() def release(self, event): event.widget.config(relief=tkinter

How to detect resizing of ttk.Treeview column?

痴心易碎 提交于 2021-01-28 09:39:33
问题 I have a ttk.Notebook and each tab contains a ttk.Treeview . All treeviews have the same columns but contain different items, like in the code below. import tkinter as tk from tkinter import ttk root = tk.Tk() notebook = ttk.Notebook(root) notebook.pack() tree1 = ttk.Treeview(notebook, columns=['a', 'b', 'c']) tree1.insert('', 'end', text='item1', values=('a1', 'b1', 'c1')) tree2 = ttk.Treeview(notebook, columns=['a', 'b', 'c']) tree2.insert('', 'end', text='item2', values=('a2', 'b2', 'c2'))

Better way to deal with Tk's keyboard events mess for numpad keys in Python+tkinter?

╄→гoц情女王★ 提交于 2021-01-28 08:49:20
问题 I am making a tkinter application that responds to individual key presses on the numeric keypad. I find that handling the tk events for the numpad keypresses are a real pain because all platforms that I tried it on result in totally different events (windows, mac, linux), and the documentation I could find is either incomplete or just wrong. My main doc source is http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/key-names.html Only Linux seems "sane" and allows you to grab the tk keysym name