Python - Having some troubles with the super function and importing [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
I have been trying to transition to Python recently but my brain isn't working well with it.
I really can't find what is the problem.
window.py
import tkinter as tk
class Window(tk.Tk):
def __init__(self):
super(Window, self).__init__()
main.py
from window import Window
win = Window()
win.mainloop()
Error message:
File "main.py", line 3, in <module>
win = Window()
File "window.py", line 5, in __init__
super(Window, self).__init__()
TypeError: super() argument 1 must be type, not classobj
Am I just being dumb?
Thank you.

If you are using a recent python version super itself needs no arguments:
class Window(tk.Tk):
def __init__(self):
super().__init__()

I am so sorry everybody ran the file with python 2.
Just typed "python3 main.py" rather than "python main.py"

Related

Why is MyApp Instance not executing on python run [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
enter image description hereI'm writing a simple code for executing an application in python kivy module I use Pycharm, the syntax is okay but its returning an error saying:
File "C:\Users\USER\PycharmProjects\pythonProject7\main.py", line 12, in <module>
TestNas().run()
TypeError: TestNas() missing 1 required positional argument: 'app'
I was expecting it to start the simple Kivy Gui but it did not.
import kivy
from kivy.app import App
from kivy.uix.label import Label
def TestNas(app):
def build(self):
return Label(Text="Test this app")
if __name__ == '__main__':
TestNas().run()
First of all TestNas() should be a class and I'm guessing it needs to be a subclass of App() that you imported. So change TestNas() to a class and capitalize App().
I think this is the code you need:
import kivy
from kivy.app import App
from kivy.uix.label import Label
class TestNas(App):
def build(self):
return Label(Text="Test this app")
if __name__ == '__main__':
TestNas().run()

How to solve "Name error" in Python tkinter programme? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
from tkinter import *
root = Tk()
mylabel = label(root, text = "What's up?")
mylabel.pack()
root.mainloop()
This is the code I used in Visual code studio. And it shows me an error:
NameError: name 'label' is not defined
What do I need to change to make this work?
pls change your code like this
mylabel = Label(root,text = '')
you should use Lable instead label

Python 3.7.0 and PyQt5.11.2: module 'PyQt5.uic' has no attribute 'loadUI' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am using the following code trying to show my Qt window:
from PyQt5 import QtCore, QtGui, QtWidgets, uic
class MyWindow(QtWidgets.QMainWindow):
def __init__(self):
super(MyWindow, self).__init__()
uic.loadUI('app.ui', self)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_)
Unfortunately, I always receive the error
AttributeError: module 'PyQt5.uic' has no attribute 'loadUI'
I have already checked whether I accidentally used Qt4 attributes, but could not find any.
It should be load.Ui, not load.UI.

error in label python, editor pycharm version [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have this:
__author__ = 'User'
from kivy.app import App
from kivy.uix.button import Label
class Hello2(App):
def build(self):
return Label()
if __name__=="__main__":
Hello2().run()
But I get an error on this line:
return Label()
And I dont know why it is an error
I have it now like this:
__author__ = 'User'
from kivy.app import App
from kivy.uix.button import Label
class Hello2(App):
def build(self):
return Label()
if __name__=="__main__":
Hello2().run()
but still the same error
Your indentation is wrong. Try reindenting like this:
__author__ = 'User'
from kivy.app import App
from kivy.uix.button import Label
class Hello2(App):
def build(self):
return Label()
if __name__=="__main__":
Hello2().run()

Simple PyQt demo from book doesn't work [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I'm brand new to GUI programming under Python and just got the book "Rapid GUI Programming with Python and QT" by Summerfield. The very first simple example ("pop-up alert in 25 lines") on page 112 works, but my attempt to exactly replicate the second example ("an expression evaluator in 30 lines") on page 116 produces only a blank window, with no visible fields for either entry or output and not even a window title. This is under Mac OS X 10.8.5 using the latest Enthought Canopy 64-bit Python installation (1.2.0.1610)
The complete contents of PyQtdemo.pyw is
from __future__ import division
import sys
from math import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Form(QDialog):
def _init__(self, parent=None):
super(Form,self).__init__(parent)
self.browser = QTextBrowser()
self.lineedit = QLineEdit("Type an expression and press Enter")
self.lineedit.selectAll()
layout = QVBoxLayout()
layout.addWidget(self.browser)
layout.addWidget(self.lineedit)
self.setLayout(layout)
self.lineedit.setFocus()
self.connect(self.lineedit, SIGNAL("returnPressed()"), self.updateUi)
self.setWindowTitle("Calculate")
def updateUi(self):
try:
text = unicode(self.lineedit.text())
self.browser.append("%s = <b>%s</b>" % (text, eval(text)))
except:
self.browser.append("<font color=red>%s is invalid!</font>" % text)
app = QApplication(sys.argv)
print dir(app)
form = Form()
form.show()
app.exec_()
It seems to me there are only the following possibilities:
there's a typo in my code that I've overlooked;
there's something wrong with how I'm invoking the script (e.g., "python PyQtdemo.pyw");
there's something wrong with my PyQt 4.10.3-1 installation;
there's an error in the book.
It's a typo in your code.
The Form.__init__ method is missing an initial underscore, and so it never gets called.
(PS: This also explains why the incorrect indentation of the updateUi method doesn't raise an AttributeError when it's referenced in self.connect).

Categories

Resources