Click here to Skip to main content
15,885,244 members

How do I make a window in tkinter canvas below the one which has a button to execute a function

Member 14169509 asked:

Open original thread
Good afternoon, everyone
I am a beginner at making guis with tkinter and Python 3.6
I wanted to make a 'Quizlet' like interface for adding questions.
How can I make the next frame appear right below the one in which I clicked +?
What I also want is to have easily accessible datat structure fot the frames.
Thank you very much!

What I have tried:

Here is my code:
Python
from tkinter import *
root = Tk()
height = root.winfo_screenheight()
canvas = Canvas(root, bd=0,width=800,height=height,bg = "blue")
screen_fit = height/105
frame_number = 2
EDIT_QUESTIONS= Label(root,text="Edit questions",font = "Courier").grid(row = 1,column = 1)
class edit:
    def __init__(self):
       canvas.grid(row=2,column=2)
       self.new_frame()
    def new_frame(self):
        def remove(window):
            pass
        def new_frame1(self):
            global frame_number
            
            frame = Frame(root)
            r = (10 + 105)* (frame_number -1)
            frame_number =  frame_number + 1
            window = canvas.create_window(25, r , anchor = "nw", window = frame,tags =(frame_number))
            text = Text(frame,height = 2)
            text.grid(row=1,column=2)
            plus = Button(frame,text="+",command = self.new_frame)
            plus.grid(row=2,column=1)            
            minus = Button(frame,text="-" )
            #minus.config(command = lambda: remove(window))
            minus.grid(row=3,column=1)

            if frame_number > int(screen_fit)or frame_number == int(screen_fit):
                def on_mousewheel(event):
                    canvas.yview_scroll(-1*(int(event.delta/120)), "units") 

                scrollbar= Scrollbar(root,orient="vertical",command=canvas.yview)
                scrollbar.grid(row=2,column=4,sticky = "ns")
                canvas.bind_all("<MouseWheel>", on_mousewheel)
                canvas.configure(scrollregion=canvas.bbox("all"),width=800,height=700) 
                canvas.configure(yscrollcommand=scrollbar.set)
        new_frame1(self)
Edit = edit()
Tags: Python (Python3.6), Canvas

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900