Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # https://www.reddit.com/r/learnpython/comments/4x2q73/python_35_tkinter_key_bindings_for_a_specific/
- #
- from tkinter import *
- from tkinter import filedialog
- from tkinter.ttk import *
- from PIL import Image, ImageTk
- import numpy as np
- class App(Tk):
- def __init__(self, *args, **kwargs):
- Tk.__init__(self, *args, **kwargs)
- Tk.wm_title(self, "GUI V0.5")
- container = Frame(self)
- container.winfo_toplevel().geometry("600x600")
- container.pack(side="top", fill="both", expand=True)
- container.grid_rowconfigure(0, weight=1)
- container.grid_columnconfigure(0, weight=1)
- self.frames = {}
- for F in (tagPage, heatPage):
- name = F.__name__
- frame = F(container, self)
- self.frames[name] = frame
- frame.grid(row=0, column=0, sticky="nsew")
- self.show_frame('tagPage')
- def show_frame(self, cont):
- frame = self.frames[cont]
- frame.tkraise()
- frame.focus_set()
- class heatPage(Frame):
- def __init__(self, parent, controller):
- Frame.__init__(self, parent)
- self.controller = controller
- self.initUI()
- def initUI(self):
- self.button = Button(self, text="Change", command=lambda:self.controller.show_frame("tagPage"))
- self.button.pack()
- self.posNegDisp = Label(self, text="heatPage:")
- self.posNegDisp.pack()
- self.bind('1', self._set_feature_Val)
- self.bind('2', self._set_feature_Val)
- def _set_feature_Val(self, event):
- if event.char == '1':
- self.featureLabel = 1
- self.posNegDisp.config(text = "heatPage:\n Positive")
- print("heatPage: positive")
- elif event.char == '2':
- self.featureLabel = -1
- self.posNegDisp.config(text = "heatPage:\n Negative")
- print("heatPage: negative")
- class tagPage(Frame):
- def __init__(self, parent, controller):
- Frame.__init__(self, parent)
- self.parent = parent
- self.controller = controller
- self.initUI()
- def initUI(self):
- self.button = Button(self, text="Change", command=lambda:self.controller.show_frame("heatPage"))
- self.button.pack()
- self.posNegDisp = Label(self, text="tagPage:")
- self.posNegDisp.pack()
- self.bind('1', self._set_feature_Val)
- self.bind('2', self._set_feature_Val)
- def _set_feature_Val(self, event):
- if event.char == '1':
- self.featureLabel = 1
- self.posNegDisp.config(text = "tagPage:\n Positive")
- print("tagPage: positive")
- elif event.char == '2':
- self.featureLabel = -1
- self.posNegDisp.config(text = "tagPage:\n Negative")
- print("tagPage: negative")
- app = App()
- app.mainloop()
Add Comment
Please, Sign In to add comment