Create notepad via python - python-3.x

Scope - Python3.10
Looking for -
add multiple editable notes in tabs. (just like notepad)
How to add a save function for a specific note
enter image description here
Attaching work done till now, Help is much appreciated
from tkinter import *
from tkinter import ttk
MainWindow = Tk() #Object#
MainWindow.geometry ('380x250') #size of object#
MainWindow.title("Bnote") #Name of object#
Menubar = Menu(MainWindow)
Appearance = Menu(Menubar,tearoff=0)
NotesArea = Text(MainWindow)
def test(Menubar):
Menubar.entryconfigure(1, label="click")
file_menu = Menu(Menubar, tearoff=False)
file_menu.add_command(label="New_Tab", command=lambda: clicked(file_menu))
Menubar.add_cascade(label="+", menu=file_menu)
scrollbar = Scrollbar(MainWindow) #adding scrollbar#
scrollbar.pack(side=RIGHT,fill=Y) #packing scrollbar#
MainWindow.config(menu=Menubar)
NotesArea = Text(MainWindow,yscrollcommand=scrollbar.set,wrap = WORD, font="Ubuntu 12")
scrollbar.config(command=NotesArea.yview) # configuring scrollbar
NotesArea.pack(fill=BOTH)
MainWindow.mainloop ()

Related

How to show tkinter buttons in mac touch bar

I have a tkinter application and want to display some of its buttons in the Mac Touch Bar.
For Example
from tkinter import *
root = Tk()
send_button = Button(text = "Send",bg = 'sky blue',fg = 'black',font = "size 15",pady = 5)
send_button.grid()
root.mainloop()
So I want to integrate the send_button to show up in the Touch Bar, so is there a way to do that in tkinter.
There is a Package called PyTouchBar. I think this would help. https://github.com/Maxmad68/PyTouchBar/wiki
As an Example:
root = Tk()
PyTouchBar.prepare_tk_windows(root)
def function(button):
print('Button clicked!')
button = PyTouchBar.TouchBarItems.Button(title='Click me!', action=function)
PyTouchBar.set_touchbar([button])
root.mainloop()

How to keep widgets when a new tab(ttk notebook) is created?

So I have a starter tab which has a textbox inside. I also want to create a new tab on the click of a button. When I create the new tab it does not show the textbox. I want all the tabs to have the same textbox and the same widgets.
Here is my code so far:
from tkinter import *
from tkinter import ttk
root = Tk()
root.geometry("600x600")
def newTab(*args): # How do I keep the textbox and other widgets in the new tabs
newFrame = Frame(root, width=500, height=500)
newFrame.pack()
tabsArea.add(newFrame, text="Untitled.txt")
button = Button(root, command=newTab).pack()
# Tab Area --- First Tab
tabsArea = ttk.Notebook(root)
tabsArea.pack(pady=15)
# Create Main Frame
frame = Frame(root)
frame.pack(pady=5)
# Add Frame to Tab
tabsArea.add(frame, text="Untitled.txt")
# Textbox
textBox = Text(frame).pack()
root.mainloop()
How do I configure the text box and widgets in the newFrame/new tab?
You need to add a new text widget in each tab. Your code is just creating empty frames. Also, you shouldn't be calling newFrame.pack() since you are adding newFrame to the notebook.
Here is a slimmed down version of your code that shows the basic concept:
from tkinter import *
from tkinter import ttk
root = Tk()
root.geometry("600x600")
def newTab(*args):
newFrame = Frame(root, width=500, height=500)
tabsArea.add(newFrame, text="Untitled.txt")
text = Text(newFrame)
text.pack(fill="both", expand=True)
button = Button(root, text="New Tab", command=newTab)
tabsArea = ttk.Notebook(root)
button.pack(side="top")
tabsArea.pack(pady=15, fill="both", expand=True)
# Add the first tab
newTab()
root.mainloop()

How do I delete a button after pressing it using tkinter in python 3?

I'm trying to make a game using Tkinter, and I'm trying to remove the buttons.
The code I'm using is:
from tkinter import *
from random import *
def ct():
textA.destroy()
tAb.destroy()
window = Tk()
textA = Text(window, width = 15, height = 1)
textA.insert(END, 'Choose a type.')
textA.config(state="disabled")
tAb = Button(window, text = 'filler', command = ct)
I don't want to change it to much too.

How to get a horizontal scrollbar in Tkinter?

I'm learning Tkinter at the moment. From my book, I get the following code for producing a simple vertical scrollbar:
from tkinter import * # Import tkinter
class ScrollText:
def __init__(self):
window = Tk() # Create a window
window.title("Scroll Text Demo") # Set title
frame1 = Frame(window)
frame1.pack()
scrollbar = Scrollbar(frame1)
scrollbar.pack(side = RIGHT, fill = Y)
text = Text(frame1, width = 40, height = 10, wrap = WORD,
yscrollcommand = scrollbar.set)
text.pack()
scrollbar.config(command = text.yview)
window.mainloop() # Create an event loop
ScrollText() # Create GUI
which produces the following nice output:
enter image description here
However, when I then try to change this code in the obvious way to get a horizontal scrollbar, it's producing a weird output. Here's the code I'm using
from tkinter import * # Import tkinter
class ScrollText:
def __init__(self):
window = Tk() # Create a window
window.title("Scroll Text Demo") # Set title
frame1 = Frame(window)
frame1.pack()
scrollbar = Scrollbar(frame1)
scrollbar.pack(side = BOTTOM, fill = X)
text = Text(frame1, width = 40, height = 10, wrap = WORD,
xscrollcommand = scrollbar.set)
text.pack()
scrollbar.config(command = text.xview)
window.mainloop() # Create an event loop
ScrollText() # Create GUI
and here's what I get when I run this:
enter image description here
You're assigning horizontal scrolling, xscrollcommand, to a vertical scrollbar. You need to modify Scrollbar's orient option to 'horizontal' which is by default 'vertical'.
Try replacing:
scrollbar = Scrollbar(frame1)
with:
scrollbar = Scrollbar(frame1, orient='horizontal')

okay so I created this code to create a GUI but i need to add buttons and when ever i try it creates a new window. what should I do?

this is my code so far o cant add buttons with out it creating more windows
////////
#import tkinter
import tkinter
#import tkmessagebox(buttons)
from tkinter import *
#create a new window
window = tkinter.Tk()
#title <------ put it before .mainloop
window.title("yeahh boiiii")
#window size
window.geometry("500x500")
#set a window icon
window.iconbitmap('N:\downloads\icon.ico.ico')#<---- 8bit file name
master = Tk()
def callback():
print ("click!")
b = Button(master, text="OK", command=callback)
b.pack()
#draws the window
window.mainloop()
////////
please help
Your problem is that you create 2 instances of Tk(). This is a bad idea, and you don't need to do it since you can make your button a child of the window object:
# Import tkinter
import tkinter as tk
# Create a new window
window = tk.Tk()
# Title <------ put it before .mainloop
window.title("yeahh boiiii")
# Window size
window.geometry("500x500")
# Set a window icon
window.iconbitmap('N:\downloads\icon.ico.ico') #<---- 8bit file name
def callback():
print ("click!")
b = tk.Button(window, text="OK", command=callback)
b.pack()
# Draw the window
window.mainloop()
I also rewrote your tkinter import, because you were importing it twice...

Resources