Issue
I am building my own python IDLE3 clone, but I'm stuck in one little thing. I can't figure out how to make a right-click Gui, that shows all those values that are implemented in the normal IDLE.
Example Picture:
I've tried many ways such as pynput or keyboard. But those are not solutions to me, if there is a library implemented in the tkinter directory please let me know.
Code
Im working on python3.x and above, on windows and linux.
#!/usr/bin/python3
# -*- encoding: utf8 -*-
import tkinter as tk
from tkinter import filedialog
class MainApplication(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
menubar = tk.Menu(self)
#### Tkinter Settings
self.title(f"untitled")
self.geometry('668x673')
#### File Menu
FileMenu = tk.Menu(menubar, tearoff=False)
FileMenu.add_command(label="New File", underline=0, accelerator="Ctrl+N")
FileMenu.add_command(label="Open...", underline=0, accelerator="Ctrl+O")
FileMenu.add_command(label="Open Module...", underline=0, accelerator="Ctrl+M")
Submenu = tk.Menu(FileMenu, tearoff=False)
FileMenu.add_cascade(label="Recent Files", menu=Submenu)
FileMenu.add_command(label="Module Browser", underline=0, accelerator="Alt+C")
FileMenu.add_command(label="Path Browser", underline=0)
FileMenu.add_separator()
FileMenu.add_command(label="Save", underline=0, accelerator="Ctrl+S")
FileMenu.add_command(label="Save As...", underline=0, accelerator="Ctrl+Shift+S")
FileMenu.add_command(label="Save Copy As...", underline=0, accelerator="Alt+Shift+S")
FileMenu.add_separator()
FileMenu.add_command(label="Print Window", underline=0, accelerator="Ctrl+P")
FileMenu.add_separator()
FileMenu.add_command(label="Close", underline=0, accelerator="Alt+F4", command=self.destroy)
FileMenu.add_command(label="Exit", underline=0, accelerator="Alt+Q", command=self.quit)
menubar.add_cascade(label="File", menu=FileMenu, underline=0)
#### Edit Menu
EditMenu = tk.Menu(menubar, tearoff=False)
EditMenu.add_command(label="Undo", underline=0, accelerator="Ctrl+Z")
EditMenu.add_command(label="Redo", underline=0, accelerator="Ctrl+Shift+Z")
EditMenu.add_separator()
EditMenu.add_command(label="Cut", underline=0, accelerator="Ctrl+X")
EditMenu.add_command(label="Copy", underline=0, accelerator="Ctrl+C")
EditMenu.add_command(label="Paste", underline=0, accelerator="Ctrl+V")
EditMenu.add_command(label="Select All", underline=0, accelerator="Ctrl+A")
EditMenu.add_separator()
EditMenu.add_command(label="Find...", underline=0, accelerator="Ctrl+F")
EditMenu.add_command(label="Find Again", underline=0, accelerator="Ctrl+G")
EditMenu.add_command(label="Find Selection", underline=0, accelerator="Ctrl+F3")
EditMenu.add_command(label="Find in Files...", underline=0, accelerator="Alt+F3")
EditMenu.add_command(label="Replace", underline=0, accelerator="Ctrl+H")
EditMenu.add_command(label="Go to Line", underline=0, accelerator="Ctrl+G")
EditMenu.add_command(label="Show Completions", underline=0, accelerator="Ctrl+space")
EditMenu.add_command(label="Expand Word", underline=0, accelerator="Alt+/")
EditMenu.add_command(label="Show Call Tip", underline=0, accelerator="Alt+backslash")
EditMenu.add_command(label="Show Surrounding Parens", underline=0, accelerator="Ctrl+0")
menubar.add_cascade(label="Edit", menu=EditMenu, underline=0)
#### Format Menu
FormatMenu = tk.Menu(menubar, tearoff=False)
FormatMenu.add_command(label="Format Paragraph", underline=0, accelerator="Alt+Q")
FormatMenu.add_command(label="Ident Region", underline=0, accelerator="Ctrl+]")
FormatMenu.add_command(label="Dedent Region", underline=0, accelerator="Ctrl+[")
FormatMenu.add_command(label="Comment Out Region", underline=0, accelerator="Alt+3")
FormatMenu.add_command(label="Uncomment Region", underline=0, accelerator="Alt+4")
FormatMenu.add_command(label="Tabify Region", underline=0, accelerator="Alt+5")
FormatMenu.add_command(label="Untabify Region", underline=0, accelerator="Alt+6")
FormatMenu.add_command(label="Toggle Tabs", underline=0, accelerator="Alt+T")
FormatMenu.add_command(label="New Indent Width", underline=0, accelerator="Alt+U")
FormatMenu.add_command(label="Strip Trailing Whitespace", underline=0)
menubar.add_cascade(label="Format", menu=FormatMenu, underline=0)
#### Run Menu
RunMenu = tk.Menu(menubar, tearoff=False)
RunMenu.add_command(label="Run Module", underline=0, accelerator="F5")
RunMenu.add_command(label="Run Customization", underline=0, accelerator="Shift+F5")
RunMenu.add_command(label="Check Module", underline=0, accelerator="Alt+X")
RunMenu.add_command(label="Python Shell", underline=0)
menubar.add_cascade(label="Run", menu=RunMenu, underline=0)
#### Options Menu
OptionsMenu = tk.Menu(menubar, tearoff=False)
OptionsMenu.add_command(label="Configure IDLE", underline=0)
OptionsMenu.add_separator()
OptionsMenu.add_command(label="Show Code Context", underline=0)
OptionsMenu.add_command(label="Show Line Numbers", underline=0)
OptionsMenu.add_command(label="Zoom Height", underline=0, accelerator="Alt+2")
menubar.add_cascade(label="Options", menu=OptionsMenu, underline=0)
#### Window Menu
WindowMenu = tk.Menu(menubar, tearoff=False)
OptionsMenu.add_command(label="Configure IDLE", underline=0)
menubar.add_cascade(label="Window", menu=WindowMenu, underline=0)
#### Help Menu
HelpMenu = tk.Menu(menubar, tearoff=False)
HelpMenu.add_command(label="About IDLE", underline=0)
HelpMenu.add_separator()
HelpMenu.add_command(label="IDLE help", underline=0)
HelpMenu.add_command(label="Python Docs", underline=0, accelerator="F1")
HelpMenu.add_command(label="Turtle Demo", underline=0)
menubar.add_cascade(label="Help", menu=HelpMenu, underline=0)
self.config(menu=menubar)
#### User-Input Service
self.text_entry = tk.Text(self, height=100, width=100)
self.scrollbar = tk.Scrollbar(self, orient=tk.VERTICAL, command=self.text_entry.yview)
self.text_entry.configure(yscrollcommand=self.scrollbar.set)
self.scrollbar.pack(side=tk.RIGHT, fill="y")
self.text_entry.pack(side=tk.LEFT, fill="x", expand=True)
### Left-Click Gui
"""
Enter all the code here
"""
if (__name__ == "__main__"):
app = MainApplication()
app.mainloop()
Solution
Found the answer already
self.bind("<Button-3>", lambda e:self.right_click)
Answered By - Alex
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.