Posts: 2
Threads: 1
Joined: May 2023
May-13-2023, 06:44 PM
(This post was last modified: May-13-2023, 07:04 PM by deanhystad.)
hello
i am new at python en gui tkinter my combobox don't show
import tkinter
from tkinter import ttk
window = tkinter.Tk()
window.title("data entry form")
frame = tkinter.Frame(window)
frame.pack()
# saving user info
user_info_frame =tkinter.LabelFrame(frame, text="user information")
user_info_frame.grid(row= 0, column=0, padx=20, pady=20)
first_name_label =tkinter.Label(user_info_frame, text="first name")
first_name_label.grid(row=0, column = 0)
last_name_label = tkinter.Label(user_info_frame, text="Last Name")
last_name_label.grid(row=0, column = 1)
first_name_entry = tkinter.Entry(user_info_frame)
last_name_entry = tkinter.Entry(user_info_frame)
first_name_entry.grid(row=1, column = 0)
last_name_entry.grid(row=1, column = 1)
title_label = tkinter.Label(user_info_frame, text="Title")
combo = ttk.combobox(window)(user_info_frame, values=["", "MR.", "MS.", "DR."])
combo.pack()
title_label.grid(row=0, column=2)
combo = ttk.combobox.grid(row=1, column=2)
combo.pack() thanks for the help
gr Paul
deanhystad write May-13-2023, 07:04 PM:Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Posts: 6,799
Threads: 20
Joined: Feb 2020
May-13-2023, 07:39 PM
(This post was last modified: May-13-2023, 07:39 PM by deanhystad.)
Your program doesn't run because it contains errors. There is no ttk.combobox. In addition, the command to make the Combobox is incorrectly formatted, and you have an extra Combobox that looks like a copy/paste error. Finally, you cannot use grid and pack to place items in a frame. One or the other, but not both.
Once you fix those problems your window still won't appear because you need to call window.mainloop() to tell tkinter to start running.
Since you are just starting learning tkinter, might I suggest start out using classes. I would subclass the Tk window to make a class for may new window.
import tkinter as tk
from tkinter import ttk
class Window(tk.Tk):
"""A window for entering user information."""
def __init__(self):
super().__init__()
self.title("Data Entry Form")
frame = tk.LabelFrame(self, text="User Information")
frame.pack(padx=10, pady=10)
tk.Label(frame, text="Title").grid(row=0, column=0)
self.title = ttk.Combobox(
frame, values=["", "MR.", "MS.", "DR."], width=4
)
self.title.grid(row=1, column=0, padx=5, pady=(0, 5))
tk.Label(frame, text="First Name").grid(row=0, column=1)
self.first_name = tk.Entry(frame, width=15)
self.first_name.grid(row=1, column=1, pady=(0, 5))
tk.Label(frame, text="Last Name").grid(row=0, column=2)
self.last_name = tk.Entry(frame, width=20)
self.last_name.grid(row=1, column=2, padx=5, pady=(0, 5))
Window().mainloop()
Posts: 2
Threads: 1
Joined: May 2023
May-19-2023, 05:59 PM
(This post was last modified: May-19-2023, 06:05 PM by deanhystad.)
Hello,
can someone tell me what i'm doing wrong the library qtconsole.qt import QtCore doesn't work already uninstalled everything and reinstalled but error remains
( import qtconsole.qt could not be resolved (pylance(reportmissingimports [ln 5, Col 6]
Thank you
gr Paul
import sys
from PyQt5.QtWidgets import QApplication, QListWidgetItem, QMainWindow
from PyQt5.uic import loadUi
from qtconsole.qt import QtCore
class Main(QMainWindow):
def __init__(self):
super(Main, self).__init__()
loadUi("main.ui", self)
todos = ["hond uitlate", "boodschappen doen","mailen", "bank gaan","huishouden"]
for todo in todos:
item = QListWidgetItem(todo)
self.todo_listWidget.addItem(item)
if __name__== '__main__':
app = QApplication(sys.argv)
window = Main()
window.show()
app.exec_()
deanhystad write May-19-2023, 06:05 PM:Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Attached Files
main.py (Size: 623 bytes / Downloads: 82)
Posts: 6,799
Threads: 20
Joined: Feb 2020
May-19-2023, 06:25 PM
(This post was last modified: May-19-2023, 06:25 PM by deanhystad.)
This is a new question. You should start a new thread.
What are you trying to do with qtconsole? There is no qtconsole.qt. I would be very surprised if there is a QtCore defined anywhere in qtconsole. QtCore is in PyQt5 along with QtWidget and QtGUI.
I used qtconsole in an application. I created a console window that I could open up to run interactive python.
from qtconsole.inprocess import QtInProcessKernelManager
from qtconsole.rich_jupyter_widget import RichJupyterWidget
from qtpy import QtWidgets
import asyncio
class Console(QtWidgets.QWidget):
def __init__(self):
super().__init__()
# start an ipython kernel in this process and let it run with the Qt event loop
self.kernel_manager = QtInProcessKernelManager()
self.kernel_manager.start_kernel()
self.kernel = self.kernel_manager.kernel
self.kernel.shell.register_magic_function(self._back, "line", "BACK")
self.kernel.shell.register_magic_function(self._where, "line", "WHERE")
self.kernel.gui = "qt4" # use qt4, but works with PySide6
# there are issues if you enter quit() or exit() in the console
# override these functions
# self.kernel.shell.push({"quit": self._console_quit, "exit": self._console_quit})
self.contexts = []
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels()
self.control = RichJupyterWidget()
self.control.kernel_manager = self.kernel_manager
self.control.kernel_client = self.kernel_client
box = QtWidgets.QVBoxLayout(self)
box.addWidget(self.control)
self.setWindowTitle("Console")
def _with(self, object):
"""Set object as namespace"""
# TBD Make this a magic function. Need to figure out how
# to evaluate "line" argument passed as argument when called.
self.contexts.insert(0, object)
return self._update_context()
def _back(self, _):
"""Restore previous namespace"""
if len(self.contexts) > 1:
self.contexts.pop(0)
return self._update_context()
return None
def _where(self, _):
"""Display context history from current to starting"""
return self.contexts
def _update_context(self):
"""Update shell to use current context"""
if len(self.contexts) == 0:
return None
obj = self.contexts[0]
if isinstance(obj, dict):
context = obj.copy()
else:
context = obj.__dict__.copy()
# TBD make WITH a magic function
context.update({"self": obj, "WITH": self._with})
self.kernel.shell.reset()
self.kernel.shell.push(context)
return obj
def setcontext(self, context):
"""Set base context"""
self.contexts = [context]
self._update_context()
def showEvent(self, event):
"""Execute when window is shown"""
self._update_context()
event.accept()
def shutdown(self):
"""Shutdown the console and stop kernels."""
self.kernel_client.stop_channels()
self.kernel_manager.shutdown_kernel()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
console = Console()
console.setWindowTitle("In process IPython Kernel with qconsole")
console.show()
sys.exit(app.exec_())
|