Tkinter-How would I create multiple pages in one window? - python

In the program I am creating, I need the user to be able to click the register/login button to move to the respective screen, I understand that I will need to use Tkinter frames to do this, but I am very lost on how to implement this.
So far, I have created the class that contains the current UI that I wish to be displayed when opening the program A design of the opening screen, but I am unsure on how to make the next page (A design of the intended next page) appear in the same window
from tkinter import *
from PIL import Image, ImageTk
import sqlite3
database_conn=sqlite3.connect('flashcard_data.db')
database_cursor=database_conn.cursor()
program_root=Tk()
class program_ui:
def __init__(self, program_window):
self.program_window=program_window
self.program_window.title('Flashcard Program')
self.program_window.iconbitmap('flashcard_program_icon.ico')
self.program_window.geometry('1248x702')
self.program_title=Label(text="Flashcard Program", fg='#173A59', font=("Franklin Gothic Medium", 70))
self.program_title.place(relx=0.5, rely=0.1, anchor='center')
self.program_register_button=Button(text="Register", fg='#173A59', font=("Franklin Gothic Medium", 20))
self.program_register_button.place(relx=0.5, rely=0.45, width=500, height=75, anchor='center')
self.program_login_button=Button(text="Log in", fg='#173A59', font=("Franklin Gothic Medium", 20))
self.program_login_button.place(relx=0.5, rely=0.65, width=500, height=75, anchor='center')
program_ui(program_root)
program_root.mainloop()

Related

Why does my button not display in GUI (Python,TK)

I am trying to create a simple GUI in Python to create buttons to access apps within my computer.
I am very new to Python & coding in general so bear with me..
I am getting 0 error messages when running the code but it just isn't displaying the button at the bottom. Here's what I have written out.
Here's a screenshot of my result
import tkinter as tk
from tkinter import filedialog, Text
import os
root = tk.Tk()
canvas = tk.Canvas(root, height=700, width=700, bg="#263D42")
canvas.pack()
frame = tk.Frame(root, bg="white")
frame.place(relwidth=0.8, relheight=0.8, relx=0.1, rely=0.1)
openFile = tk.Button(root, text="Open File", padx=10,
pady=5, fg="white", bg="#263D42")
openFile.pack()
root.mainloop()

how to lift/raise a tkinter button python

I'm trying to lift a Tkinter button so it overlaps a scrolltext in tkinter, I've tried
button.lift()
button.tag_raise
and I've also tried to make the other widget I want to be under the button lower by using
widget.lower()
widget.tag_lower()
but none of these seem to work for me, it may be because scrolltext is not a fully official tkinter widget and that may cause issues, but if anyone can help please do so! Thank you.
from tkinter import *
from tkinter import font
from tkinter.scrolledtext import ScrolledText
save_button = Button(main, fg="white",
bg="#121212", text="SAVE", font=("Microsoft JHengHei", 10),
border=0, activeforeground="white", activebackground="#141414",
relief=FLAT,
width=12,
command=save_textfile)
save.pack()
scrolltext = scrolledtext.ScrolledText(window, height=11, width=60, bg="#050505", fg="white", bd=0)
scrolltext.pack()
#this should lower the scrolltext
scrolltext.lower()
#and this should lift the save button
save_button.lift()
neither of these work.

Trying to write a tkinter popup with dynamic text and confirmation button

I am trying to make a popup for messages such as "Action completed" and I want a button on it to close the popup (A simple OK which quits only the popup). It also sometimes moves behind the window which is annoying. I have some code for the button but it has an issue with the geometry of the shape since the shape isn't exactly defined as it is variable through the size of font and text length.
import tkinter as tk
from tkinter import *
import pygame
import sys
def Text(Text_input, Font, Background, Foreground):
my_window = tk.Tk()
my_window.title(Text_input)
my_window.geometry()
help_label = tk.Label(my_window, font = Font, bg=Background, fg=Foreground, text = Text_input)
help_label.grid(row=0, column=0)
button = tk.Button(my_window, text="QUIT", fg="red", command=quit)
button.pack(side=tk.BOTTOM)
my_window.mainloop()
Text("Hello", "calibri 80", "white", "black")
From my own experience wanting to achieve this, I wrote a simple tkinter code export_success.py as follows:
from tkinter import *
from tkinter import ttk
import sqlite3
from tkinter.ttk import *
root = Tk()
root.geometry('280x100')
root.title("Export Status")
root.config(bg="")
style = ttk.Style()
label_0 = Label(root, text="Export Successful", width=20, background="white", foreground="grey15", font=("Arial, bold", 15)).place(x=50, y=23)
exit1 = Button(root, text='Exit', style='C.TButton', width=11, command=root.destroy).place(x=100, y=60)
root.mainloop()
I then just insert this code os.system('python export_success.py') at the end of my tkinker window that I'm working on.
In this case I'm exporting my information and wanted to know when it is successful.
I am not saying this is best practice and there might be other ways, I just found it to work out for me.

why tkinter button is not visible while running the code?

button is not visible while executing the program
def frame1():
# label(text displayed on the frame1)
label1 = Label(root,text="Welcome to DeciTree!\n\nThis is a desktop GUI app written in Python \nthat builds a predictive model \nusing a Decision tree algorithm called ID3\n\nClick NEXT to continue ",
anchor=CENTER, height=14, width=70, background='light green')
label1.config(font=('comic sans', 38, 'bold'))
label1.pack()
# button(next button on frame1)
button1 = Button(root, text="NEXT", height=30,width=30, command=frame2)
button1.config(font=('comic sans',20,'bold'))
button1.pack(side=RIGHT)
I can't see all of the code but have you closed it off with root.mainloop()? and if so, does it print the labels? Do you get a crash report? Maybe you have to root.update() your program to display the button? Do you have a big enough area to display the button? Does frame2 work properly?

How do you make scrolling pages in a tkinter gui with python 3, like on a website?

I am making a small program with the tkinter plugin in python. I want to make a page scrolling as you can do in the browser. Is it possible? and how do you do it?
window2 = Tk()
window2.title("RPG SM Beta 0.1")
window2.geometry('150x200')
window2.configure(background="#5C5858")
window2.iconbitmap("Logo.ico")
window2.resizable(False, False)
write1 = Text(window2, height=5, width=17, bg="white")
write1.place(x=6, y=30)
lab2 = Label(window2, text='Lorem ipsum', bg="#5C5858", fg='white', font='none 12 bold')
lab2.place(x=4, y=5)
The most command solution is to use a Canvas widget as the container. Anything added to a canvas with the create_window method will be scrollable.

Categories