0

im trying to make a simple dropdown gui,but i need some help on how to position the dropdown menu , the full code is : import tkinter as tk

from tkinter import *

root=tk.Tk()




canvas1 = tk.Canvas(root, width = 400, height = 300)
canvas1.pack()

username = tk.Entry(root)
canvas1.create_window(200,140, window=username)
canvas1.create_text(100,140,fill="darkblue",text="username")

password = tk.Entry(root)
canvas1.create_window(200,180,window=password)
canvas1.create_text(100,180,fill="darkblue",text="password")

variable = StringVar(root)
variable.set("Facebook")

w=OptionMenu(root , variable, "Facebook","Twitter","Spotify","Swiggy")
w.pack()

button1= tk.Button(text='Go')
canvas1.create_window(250,250, window=button1)

root.mainloop()

the dropdown menu was obtained by using the OptionMenu but im unable to change its position, i need help with that code for just the OptionMenu:

from Tkinter import *

master = Tk()

variable = StringVar(master)
variable.set("one") # default value

w = OptionMenu(master, variable, "one", "two", "three")
w.pack()

mainloop()
CEH
  • 5,358
  • 2
  • 15
  • 36
  • 2
    Why are you unable to change it's position? Where do you want it? It looks like you're succesfully calling `pack`, have you tried the various options to `pack`, or explored using `grid`? – Bryan Oakley Nov 20 '19 at 16:49
  • Read [gui layout using frames and grid](https://stackoverflow.com/questions/34276663/tkinter-gui-layout-using-frames-and-grid/34277295#34277295) – stovfl Nov 20 '19 at 16:58

1 Answers1

0

You just need to add this statement canvas1.create_window(250,250, window=w) at the end of this code:

from Tkinter import *

master = Tk()

variable = StringVar(master)
variable.set("one") # default value

w = OptionMenu(master, variable, "one", "two", "three")
w.pack()
Tonechas
  • 12,665
  • 15
  • 42
  • 74
  • This doesn't quite solve the problem. Why are you trying to add the `OptionMenu` to a `Canvas` after it has already been added to a `Tk` window? This doesn't explain _how_ to change the `OptionMenu`'s position. See [answer] for more information on writing good answers. – Sylvester Kruin Mar 30 '22 at 21:56